PHP Extended Class

What is the difference between a standard clclass function and an extended class function ? Please give short examples.
Thanks,
Michael
mhoggatt1Asked:
Who is Participating?
 
JB04Commented:
Them webpages provide plenty of examples, I got the exxample below from http://php.net/manual/en/keyword.extends.php


<?php
class Named_Cart extends Cart {
   var $owner;
 
   function set_owner ($name) {
       $this->owner = $name;
   }
}
?>


You would have to have the class named Cart already defined to use the example
0
 
JB04Commented:
Im guessing that was  a typo and you never meant clclass but instead meant class


The difference looks like this,



class foo {

   function test()
   {
   }

}


class bar extends foo {

}



The first is a standard class while the second extends the first class, you can get detailed info about this from the PHP manual but basically an extended class inherits all the methods and properties of the class its extending, in the above example the bar class will have the method test available to it because it inherits from foo


PHP version 4 has limited object support while PHP 5 has much more support for object, the manual also reflects this:-


PHP 4 - http://php.net/oop
PHP 5 - http://php.net/oop5



James
0
 
mhoggatt1Author Commented:
Hi James,
   Yes it was a typo. I meant to say 'a standard class function'. Could add some code to make the extended class execute some code so I can see what it would look like ?
Thanks,
Michael
0
 
mhoggatt1Author Commented:
Does the extended class basically make the function accessible from anywhere in the program ?
Thanks,
Michael
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.