ID:               33436
 User updated by:  j dot amel83 at gmail dot com
 Reported By:      j dot amel83 at gmail dot com
-Status:           Bogus
+Status:           Closed
 Bug Type:         Class/Object related
 Operating System: Win XP, Apache 2.0.54
 PHP Version:      5.0.4
 New Comment:

oh, i wrote bad code for this bug see this one:
i want to have max one instance of Session class an i found ever things
right, thanks.
<?php
class Session {

        protected static $instance = null;
        
        public static function getSession() {
                
                if(self::$instance == null) {
                        
                        $class = __CLASS__;
                        self::$instance = new $class();
                        
                }
                return self::$instance;
                
        }
        
        private function __construct() {
        
                /*
                 *
                 *
                 */
        
        }
        
        public function __clone() {

                throw new Exception('Clone not supported Exception');

        }
        
}
$s1 = Session::getSession();
$s2 = clone $s1;
?>


Previous Comments:
------------------------------------------------------------------------

[2005-06-22 19:42:22] [EMAIL PROTECTED]

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.

------------------------------------------------------------------------

[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

Reply via email to