php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27074 __clone() has problem with the vision
Submitted: 2004-01-28 08:55 UTC Modified: 2004-02-03 13:51 UTC
From: andrey@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2004-01-28 (dev) OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: andrey@php.net
New email:
PHP Version: OS:

 

 [2004-01-28 08:55 UTC] andrey@php.net
Description:
------------
In the following code __clone() have problems with member variables of type
object ($this->obj is null). If the comment is removed from the call to
__clone2() in __clone() then __clone2() also has problems with the vision. On
the other hand __clone2() has no problems when called externally. The difference between the expected and the actual result is the second call to print_r()

Reproduce code:
---------------
<?php
class clone_example {
        private $pub = 2;
        private $obj = NULL;

        function clone_example($obj) {
                $this->obj = $obj;
        }

        function __clone() {
                print_r($this);
//                $this->__clone2();
        }
        function __clone2() {
                print_r($this);
        }
}

class fubar {
        public $v = array(1,2,3);
}
$fu = new fubar();
$a = new clone_example($fu);
$a->__clone2();
$a->__clone();
$a->__clone2();
?>

Expected result:
----------------
clone_example Object
(
    [pub:private] => 2
    [obj:private] => fubar Object
        (
            [v] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)
clone_example Object
(
    [pub:private] => 2
    [obj:private] => fubar Object
        (
            [v] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)
clone_example Object
(
    [pub:private] => 2
    [obj:private] => fubar Object
        (
            [v] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)

Actual result:
--------------
clone_example Object
(
    [pub:private] => 2
    [obj:private] => fubar Object
        (
            [v] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)
clone_example Object
(
    [pub:private] => 2
    [obj:private] =>
)
clone_example Object
(
    [pub:private] => 2
    [obj:private] => fubar Object
        (
            [v] => Array
                (
                    [0] => 1
                    [1] => 2
                    [2] => 3
                )

        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-03 13:51 UTC] andi@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Check bug report http://bugs.php.net/?id=26794
We rewrote the __clone() support. If you still have this problem then please reopen the bug report
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 12:01:27 2024 UTC