PHP Extended Class

Posted on 2006-04-19
Last Modified: 2008-03-17
What is the difference between a standard clclass function and an extended class function ? Please give short examples.
Question by:mhoggatt1
    LVL 7

    Expert Comment

    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 -
    PHP 5 -


    Author Comment

    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 ?
    LVL 7

    Accepted Solution

    Them webpages provide plenty of examples, I got the exxample below from

    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

    Author Comment

    Does the extended class basically make the function accessible from anywhere in the program ?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now