#33436 [Opn->Bgs]: clone problem

From: Date: Wed, 22 Jun 2005 17:42:23 +0000
Subject: #33436 [Opn->Bgs]: clone problem
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80849@lists.php.net to get a copy of this message
ID: 33436 Updated by: tony2001@php.net Reported By: j dot amel83 at gmail dot com -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Win XP, Apache 2.0.54 PHP Version: 5.0.4 New Comment: Remove the last line (the one with "clone") and you'll see the very same result. Clone has nothing to do with it - you're trying to instantiate class with private constructor. Previous Comments: ------------------------------------------------------------------------ [2005-06-22 17:44:21] j dot amel83 at gmail dot com Description: ------------ If there is protected/private constructor method, there is no way to clone the class, it’s seems that the clone method try to create new object from the class using constructor and then set it’s properties like the cloned one. Reproduce code: --------------- <?php class Test { protected $name; private function __construct() { $this->name = 'ali'; } public function __clone() { throw new Exception('Clone not supported Exception'); } } $t1 = new Test(); $t2 = clone $t; ?> Expected result: ---------------- Fatal error: Uncaught exception 'Exception' with message 'Clone not Supported Exception' in D:\WebServerRoot\FrameWork\test.php:15 Stack trace: #0 Actual result: -------------- Fatal error: Call to private Test::__construct() from context '' in D:\WebServerRoot\FrameWork\test.php on line 15 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33436&edit=1

« previous php.bugs (#80849) next »