The patch showcase: self

at 2005-01-09 in PHP5 by friebe (0 comments)

The keyword self can be used like $this for static classes - the problem with the current implementation is that it does not respect the "runtime class" (don't know how to describe this any better...). See also this discussion on the PHP developer's mailinglist.

As of today the patch fixes this. The following now works as one would intuitively expect:

<?php 
class A {
protected
static $instance = NULL;

public
static function getInstance() {
if
(!self::$instance) {
self::
$instance= new self();
}
return self::
$instance;
}
}

class B extends A { }

echo get_class
(B::getInstance());
?>

This outputs "B" - credits go to Alex:)



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases

Related

Find related articles by a search for «The».