Edit report at http://bugs.php.net/bug.php?id=52182&edit=1

 ID:          52182
 Comment by:  olamedia at gmail dot com
 Reported by: olamedia at gmail dot com
 Summary:     get_object_by_id and get_object_id
 Status:      Bogus
 Type:        Feature/Change Request
 Package:     Unknown/Other Function
 PHP Version: 5.3.2

 New Comment:

2 johannes

So you think, that I need to force call $object->invalidate() / garbage
collection 

each time I want no memory leaks? Well, I don't need a "unique id", just
"lifetime 

unique id".

spl_object_hash() don't have a reverse function spl_get_object_by_hash()


Previous Comments:
------------------------------------------------------------------------
[2010-06-25 13:17:14] johan...@php.net

Your design looks broken. Why should unset a random pointer to the
object destroy it? If you really need to unset them - which I'd most
likely consider broken design - add a method to invalidate it this ...



If you really want to do this the needed function is available -
spl_object_hash().



But mind that we don't have any true unique identifier - once an object
is destroyed it's ID might be re-used by others.

------------------------------------------------------------------------
[2010-06-25 12:35:55] olamedia at gmail dot com

Description:
------------
Requesting new functions:

get_object_id() to get identifier of the object like in var_dump()
(Object #XXX)

get_object_by_id() to get object by identifier



Related bug in test script



Test script:
---------------
class a{

  protected $b;

  public function __construct($b){

     $this->b = $b;

  }

}

class b{

}

$b = new b()

$a = new a($b);

unset($b); // __destruct will not be called because of link left in $a

Expected result:
----------------
class a{

  protected $b;

  public function __construct($b){

     $this->b = get_object_id($b); // integer

  }

  public function getB(){

    return get_object_by_id($this->b);

  }

}

class b{

}

$b = new b()

$a = new a($b);

var_dump($a->getB()); // Object #

unset($b); // __destruct will be called because no links left

var_dump($a->getB()); // boolean false



------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52182&edit=1

Reply via email to