note 101309 modified in language.oop5.late-static-bindings by danbrown

From: Date: Thu, 09 Dec 2010 15:07:58 +0000
Subject: note 101309 modified in language.oop5.late-static-bindings by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174744@lists.php.net to get a copy of this message
consider this: <?php class A { // some stuff.... public static function getInstance() { return new self(); } } class B extends A { //stuff... } $obj = B::getInstance(); //versus class A { // some stuff.... public static function getInstance() { return new static(); } } class B extends A { //stuff... } $obj = B::getInstance(); ?> also works the same way with static variables and constants --was-- consider this: class A { // some stuff.... public static function getInstance() { return new self(); } } class B extends A { //stuff... } $obj = B::getInstance(); //versus class A { // some stuff.... public static function getInstance() { return new static(); } } class B extends A { //stuff... } $obj = B::getInstance(); http://php.net/manual/en/language.oop5.late-static-bindings.php

« previous php.notes (#174744) next »