?
Solved

know to go back to DocumentObject::getGroup

Posted on 2014-04-23
5
Medium Priority
?
210 Views
Last Modified: 2014-04-28
<?php
abstract class DomainObject {
    private $group;
    public function __construct() {
        $this->group = static::getGroup();
    }

    public static function create() {
        return new static();        
    }

    static function getGroup() {
        return "from default"; 
    }
}

class User extends DomainObject {
}

class Document extends DomainObject {
    static function getGroup() {
        return "from document"; 
    }
}

class SpreadSheet extends Document {
}
echo'<pre>';
$userCreate=User::create();
print_r($userCreate);
$spreadSheetCreate=SpreadSheet::create();
print_r($spreadSheetCreate);
echo'</pre>';
?>

Open in new window


how does
$spreadSheetCreate=SpreadSheet::create();
know to go back to
DocumentObject::getGroup
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 1000 total points
ID: 40019238
Through inheritance. The Spreadsheet class inherits Document's methods.
This includes the getGroup() method (which is overriden in the Document class).

HTH,
Dan
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40019814
For better or worse, computer programming is a "precise science" requiring that we use the right names for variables and functions.No such method
0
 

Author Comment

by:rgb192
ID: 40021859
sorry I meant
DomainObject::getGroup
not
DocumentObject::getGroup



go to different getGroup
$userCreate=User::create();
$spreadSheetCreate=SpreadSheet::create();

Through inheritance. The Spreadsheet class inherits Document's methods.
This includes the getGroup() method (which is overriden in the Document class).

Is this example of late static binding?
0
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 40022403
Late Static Binding is a bit different from Inheritance.  If you read these two man pages carefully and find yourself wondering about how a programmer can keep track of what software is being executed, you're not alone.  Mercifully, PHP did not introduce multiple inheritance!

I have a shovel and a rake.  If I really try, I can gather leaves with the shovel and dig a hole with the rake.  But doing either would be a "run-time error."  That is kind of how I think of some of the more arcane programming constructs.  The simpler and more obvious I can make my code, the more likely I will finish the task quickly and accurately.
0
 

Author Closing Comment

by:rgb192
ID: 40028773
thanks for examples about calling methods.
0

Featured Post

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

801 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