php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29098 "new" operator crashes script
Submitted: 2004-07-11 20:35 UTC Modified: 2005-01-22 01:00 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: antonr at game dot permonline dot ru Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 5CVS-2004-07-12 (dev) OS: Irrelevant
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: antonr at game dot permonline dot ru
New email:
PHP Version: OS:

 

 [2004-07-11 20:35 UTC] antonr at game dot permonline dot ru
Description:
------------
When "new" operator appears without "=" operator, it is possibly crashes php

Reproduce code:
---------------
<?php
  class ParentClass
    { private $child;
      public function __construct($child)
        { echo "ParentClass::__construct()<br>\n";
          $this->child = $child;
          $child->setParent($this);
        }
      public function __destruct()
        { echo "ParentClass::__destruct()<br>\n";
          unset($this->child);
        }
    }

  class ChildClass
    { private $parent;
      public function setParent($parent)
        { echo "ChildClass::setParent()<br>\n";
          $this->parent = $parent;
        }
      public function __destruct()
        { echo "ChildClass::__destruct()<br>\n";
          unset($this->parent);
        }
    }

  new ParentClass(new ChildClass());
?>


Expected result:
----------------
    ParentClass::__construct()
    ChildClass::setParent()

and possibly
    ChildClass::__destruct()
    ParentClass::__destruct()


Actual result:
--------------
php crashes

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-11 23:07 UTC] curt@php.net
How do you mean possibly? My output with script given:

PHP Fatal error:  Call to a member function setParent() on a non-object in test.php on line 7
ParentClass::__destruct()<br>
 [2004-07-12 06:58 UTC] antonr at game dot permonline dot ru
On last snap Jul 12, 2004 02:30 GMT

php-cgi.exe outputs nothing to browser and crushes.

php.exe outputs:
ChildClass::__destruct()<br>
ParentClass::__construct()<br>
and then crushes.

One else bug: why ChildClass::__destruct are called before ParentClass::__construct? You see, the reference on ChildClass instance must be passed to ParentClass::__construct.

If I change the line 
new ParentClass(new ChildClass());
to
$a = new ParentClass(new ChildClass());


php-cgi.exe and php.exe output same result:

ParentClass::__construct()<br>
ChildClass::setParent()<br>
ParentClass::__destruct()<br>
ChildClass::__destruct()<br>

and not crash.
 [2004-07-12 19:47 UTC] antonr at game dot permonline dot ru
Linux Mandrake 10.0: the same behaviour.
 [2004-07-12 19:56 UTC] antonr at game dot permonline dot ru
Bug is independent of OS
 [2004-07-13 16:11 UTC] fixxxer at php5 dot ru
Updating to the latest snapshot seems to fix the problem.
 [2004-07-13 16:40 UTC] tony2001@php.net
Reproducable under Win2k with latest snapshot, but works ok under Linux.
Valgrind doesn't show any errors about it.
 [2005-01-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC