Activity Stream
48,167 MEMBERS
6739 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1.     
    #1
    Member
    Website's:
    Doxsters.net

    Default What is the point of the php extends in relation to classes?

    I just don't get it. Why create one class, eg
    PHP Code: 
    class user{
    function 
    login(){
    //login stuff
    }

    then use the extends keyword like so
    PHP Code: 
    class admin extends user{
    function 
    admin(){
    //admin stuff
    }

    Why not just put it in one big class and only call the admin function for when they are needed?
    timtamboy63 Reviewed by timtamboy63 on . What is the point of the php extends in relation to classes? I just don't get it. Why create one class, eg class user{ function login(){ //login stuff } } then use the extends keyword like so Rating: 5

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):[email protected]

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  2.   Sponsored Links

  3.     
    #2
    Member
    I'll answer your question with another question: "What if you have 1 milion types of users. Would you copy paste the same functions over and over again on all files?!"

    This is one of the basics of OOP.

    Quick reference for intelectual answer:
    http://en.wikipedia.org/wiki/Inherit...d_programming)

  4.     
    #3
    Member
    Website's:
    Doxsters.net
    Ooh, I see, thanks, I guess I wasn't thinking of it in terms of larger applications.

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):[email protected]

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  5.     
    #4
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    An Example:

    PHP Code: 
    class Curl
    {
        var 
    $url,$postparams;
        protected 
    $curl;

        private function 
    __construct()
        {
             
    $this->curl curl_init();
        }
         
        public function 
    submit()
        {
            
    //Code to submit
        
    }

        public function 
    request()
        {
            
    //Code to request
        
    }

    then you would use that as your base and create many smaller classes to use that code

    PHP Code: 
    class SubmitPost extends Curl
    {
         public function 
    __construct($url,$data)
         {
              
    $this->url $url;
              
    $this->postparams $data;
         }

         public function 
    go()
         {
             return 
    $this->submit();
         }

    aswell as:

    PHP Code: 
    class RequestPage extends Curl
    {
         public function 
    __construct($url)
         {
              
    $this->url $url;
         }

         public function 
    go()
         {
             return 
    $this->request();
         }

    Then you have organized code for particular task and not one massive class that's jumbled up with many different things.
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  6.     
    #5
    Member
    Website's:
    Doxsters.net
    I see, thanks

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):[email protected]

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  7.     
    #6
    Respected Developer
    Website's:
    X4B.org
    Most commonly used for shared elements of code between multiple classes. e.g a Base class might have a method for url encoding and the DDL class might have a method retuning a download url (urlencoded)

  8.     
    #7
    You can call me G
    Speaking from the OOP perspective, inheritance is a very essential feature. Let me generalize this.

    Say you have a class called flowers. Now you create another class called Rose. now the Rose class has ALL the properties of flowers so it "inherits" it from the parent aka the flowers class and the rose class is unique in itself.. Hope that makes it clear.. this was the way I was taught in grade 10 while learning Java



    My Langotiya Yaars (Chaddi buddies): JmZ, humour, Chutad, Esotorisk, l0calhost, Daniel, Mind Freak?, TLK, Amz

  9.     
    #8
    Member
    Quote Originally Posted by gunda316 View Post
    Speaking from the OOP perspective, inheritance is a very essential feature. Let me generalize this.

    Say you have a class called flowers. Now you create another class called Rose. now the Rose class has ALL the properties of flowers so it "inherits" it from the parent aka the flowers class and the rose class is unique in itself.. Hope that makes it clear.. this was the way I was taught in grade 10 while learning Java
    Well explained, I like the way you explain gunda
    I am the TharkiBaba >_> Oh well thats my websites name -_-

  10.     
    #9
    Member
    Website's:
    Doxsters.net
    ahh, yeah that does make it pretty clear. Also, do i use the parent keyword to access functions from the parent class?

    Need a Designer/Web Developer? Click Me

    MSN: PM me for it.
    Email(Preferred):[email protected]

    "Power Corrupts. Absolute Power Corrupts Absolutely"

  11.     
    #10
    Member
    Website's:
    Installtheworld.blogspot.com Redswitches.com
    gunda316 you were taught JAVA in grade 10

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Microsoft extends Windows 7 support to 2020
    By ShareShiz in forum News & Current Events
    Replies: 10
    Last Post: 24th Feb 2012, 03:18 PM
  2. What's the point of...
    By tres in forum General Discussion
    Replies: 3
    Last Post: 30th Oct 2010, 01:02 AM
  3. C# Basics I - Classes in C#
    By iFlames in forum Web Development Area
    Replies: 9
    Last Post: 29th Jun 2010, 05:33 PM
  4. LE with live-point.net
    By SpiderZq in forum Traffic Market (Buy, Sell and Trade)
    Replies: 3
    Last Post: 2nd Sep 2009, 09:08 PM
  5. PHP Tutorial (Creating Classes)
    By litewarez in forum Tutorials and Guides
    Replies: 0
    Last Post: 14th May 2009, 11:40 AM

Tags for this Thread

BE SOCIAL