Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:16356 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99649 invoked by uid 1010); 2 Jun 2005 14:28:27 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 90277 invoked from network); 2 Jun 2005 14:24:10 -0000 Received: from unknown (HELO pb1.pair.com) (127.0.0.1) by localhost with SMTP; 2 Jun 2005 14:24:10 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:35872] helo=mail.zend.com) by pb1.pair.com (ecelerity 1.2 r(5656M)) with SMTP id 3F/42-12977-8861F924 for ; Thu, 02 Jun 2005 10:24:09 -0400 Received: (qmail 22185 invoked from network); 2 Jun 2005 14:24:04 -0000 Received: from internal.zend.office (HELO hp.home) (10.1.1.1) by internal.zend.office with SMTP; 2 Jun 2005 14:24:04 -0000 Date: Thu, 2 Jun 2005 18:24:04 +0400 To: Jean-Francois Levesque Cc: internals@lists.php.net Message-ID: <20050602182404.381a0c0c.antony@zend.com> In-Reply-To: <38.C1.16559.3240F924@pb1.pair.com> References: <38.C1.16559.3240F924@pb1.pair.com> X-Mailer: Sylpheed version 1.9.12 (GTK+ 2.6.4; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PHP5, objects not passed by reference?!? From: antony@zend.com (Antony Dovgal) On Thu, 02 Jun 2005 09:05:24 -0400 Jean-Francois Levesque wrote: > Hi! > > In PHP5, the objects are supposed to be passed by reference, right? I > try to use a singleton pattern but it's not working. I just compile the > lastest php version (5.0.4) and I still have the problem. > > My code : > > class Example > { > // Hold an instance of the class > private static $instance; > public $testvar = 'init'; > > // The singleton method > public static function singleton() > { > if (!isset(self::$instance)) { > $c = __CLASS__; > self::$instance = new $c; > } > > return self::$instance; > } > // Prevent users to clone the instance > public function __clone() > { > trigger_error('Clone is not allowed.', E_USER_ERROR); > } > } > > $test = Example::singleton(); > $test2 = Example::singleton(); > > $test->testvar = 1; > $test2->testvar = 2; > > echo $test->testvar." ; ".$test2->testvar; > > ?> > > > Output : > > Fatal error: Clone is not allowed. in > /usr/home/usagers/linux/step_html/stationnement/test.php on line 21 > > > Phpinfo : http://step.polymtl.ca/~linux/stationnement/phpinfo.php > > Should I set something in the php.ini? What can I do? I get "2 ; 2" and no error with latest snapshots of 5.0.5-dev and HEAD. Check if you have zend.ze1_compatibility_mode Off. -- Wbr, Antony Dovgal aka tony2001 antony@zend.com