php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30533 Parentheses around returned object cause a parse error
Submitted: 2004-10-22 18:58 UTC Modified: 2004-10-22 19:14 UTC
From: tompaw at irc dot pl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5CVS-2004-10-22 (dev) OS: Windows XP SP2 CORP ENU
Private report: No CVE-ID: None
 [2004-10-22 18:58 UTC] tompaw at irc dot pl
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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-10-22 19:14 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

,
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 12:01:27 2024 UTC