|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-08 15:14 UTC] proton at fangen dot net
Description:
------------
When creating an object, each created object should have a unique (zend engine 2 internal) Object ID, right? The code below always prints "Object id #1", i.e. the objects have the same ID. Although they are instances of an empty (no methods or properties) class, I had the same problem with classes that did have methods and/or properties.
Here's a short script that reproduces the problem:
Reproduce code:
---------------
class MyClass
{
}
function test()
{
$c = new MyClass();
print $c; // Will always print "Object id #1"
}
test();
test();
Expected result:
----------------
Object id #1
Object id #2
Actual result:
--------------
Object id #1
Object id #1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Apr 01 10:00:02 2026 UTC |
This is not a bug, run this code and you'll see why: <?php class MyClass { function __destruct() { echo "dtor\n"; } } function test() { $c = new MyClass(); print $c."\n"; // Will always print "Object id #1" } test(); test(); ?>