From:             queenzeal at gmail dot com
Operating system: 
PHP version:      5.3.0
PHP Bug Type:     Feature/Change Request
Bug description:  __clone and __toString behave inconsistently

Description:
------------
__toString() can be called directly but __clone() cannot.  It seems like
this behavior ought to be consistent.  Either both can be called directly
or neither can be called directly.

__clone()'s current behavior is documented in
<http://php.net/language.oop5.cloning> with the following:

"An object's __clone() method cannot be called directly."

The only reason I can figure for that is that without it, it'd be possible
to clone a cloned object redundantly. eg. $a = clone $b->__clone().  That
said, it seems to me like this can be done, already, with $a = clone clone
$b, so that seems like a non-issue.

Reproduce code:
---------------
class a
{
    function __toString() {
        return 'a';
    }

    function __clone() {
        return this;
    }
}

$a = new a();

echo "$a\r\n";
echo $a->__toString() . "\r\n";

$b = clone $a;
$b = $a->__clone();

Expected result:
----------------
a
a

Actual result:
--------------
Fatal error: Cannot call __clone() method on objects - use 'clone $obj'
instead
in C:\php\test.php on line 20

-- 
Edit bug report at http://bugs.php.net/?id=49987&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49987&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49987&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49987&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49987&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49987&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49987&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49987&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49987&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49987&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49987&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49987&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49987&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49987&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49987&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49987&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49987&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49987&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49987&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49987&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49987&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49987&r=mysqlcfg

Reply via email to