php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22801 pb with __clone()
Submitted: 2003-03-20 03:51 UTC Modified: 2003-06-04 22:21 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (33.3%)
From: fabrice dot lecoz at zedesk dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2003-03-20 (dev) OS: win XP / Linux
Private report: No CVE-ID: None
 [2003-03-20 03:51 UTC] fabrice dot lecoz at zedesk dot com
return of the __clone() method crash.

<?php
class test {
    var $name;
    
    function __construct($name) {
        $this->name = $name;
    }
    
    function __clone() {
        echo "cloning ...\n";
        $this->name = "test ".$that->name;
    }
}

$test = new test("essai");
$test1 = $test;
$test2 = $test->__clone();
$test1->name = "arthur";
echo "test  : $test->name\n";
echo "test2 : $test2->name\n";
?>

-- expect --
cloning ...
test  : arthur
test2 : test essai

-- result --
cloning ...

php crash
AppName: php.exe	 AppVer: 5.0.0.0	 ModName: php4ts.dll ModVer: 5.0.0.0	 Offset: 000ee8a5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-21 01:04 UTC] magnus@php.net
0x08276b1f in zend_do_fcall_common_helper (execute_data=0xbfffd1e0, op_array=0x4198d888) at /opt/dev/php/php5/Zend/zend_execute.c:2628
2628            if (EX(function_state).function->type == ZEND_INTERNAL_FUNCTION) {

(gdb) bt full
#0  0x08276b1f in zend_do_fcall_common_helper (execute_data=0xbfffd1e0, op_array=0x4198d888) at /opt/dev/php/php5/Zend/zend_execute.c:2628
        original_return_value = (zval **) 0x0
        current_scope = (zend_class_entry *) 0x0
        current_this = (zval *) 0x0
        return_value_used = 1
        active_namespace = (zend_namespace *) 0x83c3bf4
#1  0x08277136 in zend_do_fcall_by_name_handler (execute_data=0xbfffd1e0, op_array=0x4198d888) at /opt/dev/php/php5/Zend/zend_execute.c:2731
No locals.
#2  0x08272472 in execute (op_array=0x4198d888) at /opt/dev/php/php5/Zend/zend_execute.c:1242
        execute_data = {opline = 0x4198df80, function_state = {function_symbol_table = 0x4198e960, function = 0x0, reserved = {0x0, 0x0, 0x4198d888, 0x0}}, fbc = 0x0,
  fbc_constructor = 0x41990dcc, op_array = 0x4198d888, object = 0x0, Ts = 0xbfffcebc, original_in_execution = 0 '\0', calling_scope = 0xbffff560, prev_execute_data = 0x0}
#3  0x0825dcde in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /opt/dev/php/php5/Zend/zend.c:986
        files = 0xbfffd294 ""
        i = 1
        file_handle = (zend_file_handle *) 0xbffff560
        orig_op_array = (zend_op_array *) 0x0
        local_retval = (zval *) 0x0
#4  0x0821fffa in php_execute_script (primary_file=0xbffff560) at /opt/dev/php/php5/main/main.c:1587
        orig_bailout = {{__jmpbuf = {1086526096, 1073819680, -1073744396, -1073744472, -1073744928, 136842824}, __mask_was_saved = 0, __saved_mask = {__val = {
        0 <repeats 32 times>}}}}
        orig_bailout_set = 1 '\001'
        prepend_file_p = (zend_file_handle *) 0x0
        append_file_p = (zend_file_handle *) 0x0
        prepend_file = {type = 1 '\001', filename = 0x8493ef8 "STDIN", opened_path = 0x6 <Address 0x6 out of bounds>, handle = {fd = 138204648, fp = 0x83cd5e8, stream = {
      handle = 0x83cd5e8, reader = 0x3, closer = 0xc433217b, interactive = -1073744936}}, free_filename = 0 '\0'}
        append_file = {type = 1 '\001', filename = 0x8493f60 "STDOUT", opened_path = 0x7 <Address 0x7 out of bounds>, handle = {fd = 136489788, fp = 0x822ab3c, stream = {
      handle = 0x822ab3c, reader = 0x1, closer = 0, interactive = 1}}, free_filename = 7 '\a'}
        old_cwd = 0xbfffd29c ""
        old_primary_file_path = 0xbffff76a "22801.php"
        retval = 0

 [2003-04-17 12:46 UTC] tim at timcrider dot com
I get almost the same result using php5-200304171330, on Red Hat 8.0. The main difference is mine seg faults when trying to use __clone

<?php

class a
{ 
   function __construct($n)
   {
      $this->name = $n;
   }
  
   function __clone() 
   {
      print "cloning...\n";
      $this->name = "test".$that->name;
   }
} 
  
 $x = New a("tito");
  
 $y1 = $x;
  
 $y2 = $x->__clone();
  
 print "test1 {$y1->name}\n";    
 print "test2 {$y2->name}\n";      
  
?>

[Output]
(towely) superunknown# /php5/bin/php -q clone.php 
cloning...
Segmentation fault
 [2003-06-04 22:21 UTC] sterling@php.net
fixed in cvs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 21 11:01:34 2024 UTC