|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-10-22 19:14 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 07:00:01 2025 UTC |
Description: ------------ I use Singleton classes in my code. In each of them there must be a function that returns the instance of the object of that class (or creates that object before). The problem occurs, when I try to put that method insinde parentheses, like (MobilDB::GI())->test(); in the following example. Please notice, that MobilDB::GI()->test(); works perfectly, so the problem seems to be related to the parentheses around MobilDB::GI(). Reproduce code: --------------- class MobilDB { private static $instance = null; private function __construct() { echo "const"; } public static function GI() { if (self::$instance == null) { self::$instance = new MobilDB; } return self::$instance; } function test() { echo "test"; } } (MobilDB::GI())->test(); Expected result: ---------------- I expected the constructor from the MobilDB class to be run (as this is the first instance of GI() function and appropriate object must be created) and then the test() method from the same class to be run. The expected output was "consttest". Actual result: -------------- Parse error: parse error, unexpected T_OBJECT_OPERATOR in D:\www\mobil\m.php on line 8