note 79966 added to language.oop5.patterns
| From: | seguro at unicar dot org dot ua | Date: | Fri, 21 Dec 2007 10:57:58 +0000 |
| Subject: | note 79966 added to language.oop5.patterns | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133843@lists.php.net to get a copy of this message | ||
There is very interesting result of this script. Object created, but not saved in variable... Any
ideas?
<?php
class Singletone
{
private static $instance;
protected function __construct()
{
print 'class Singletone';
}
public static function init($className=__CLASS__)
{
if(!isset(self::$instance))
self::$instance = new $className;
return self::$instance;
}
}
abstract class Session extends Singletone
{
}
final class SessionMemcache extends Session
{
protected function __construct()
{
print('Session memcached');
}
public static function init()
{
parent::init(__CLASS__);
}
public function test()
{
print 'TEST from SessionMemcache object';
}
}
$a = SessionMemcache::init(); //print msg from constructor
$a->test(); //Fatal error: Call to a member function test() on a non-object
?>
----
Server IP: 88.81.249.248
Probable Submitter: 195.200.64.186
----
Manual Page -- http://www.php.net/manual/en/language.oop5.patterns.php
Edit -- https://master.php.net/note/edit/79966
Del: integrated -- https://master.php.net/note/delete/79966/integrated
Del: useless -- https://master.php.net/note/delete/79966/useless
Del: bad code -- https://master.php.net/note/delete/79966/bad+code
Del: spam -- https://master.php.net/note/delete/79966/spam
Del: non-english -- https://master.php.net/note/delete/79966/non-english
Del: in docs -- https://master.php.net/note/delete/79966/in+docs
Del: other reasons-- https://master.php.net/note/delete/79966
Reject -- https://master.php.net/note/reject/79966
Search -- https://master.php.net/manage/user-notes.php