var_dump(object) returns: object()#1
I really want to know what's the difference between object()#1, object()#2, and object()#3.
Any help is appreciated.
For objects with identical information (same class, same properties) it allows to determine whether they are the same instance. For example:
$a = new DateTime();
$b = $a; // Link to same instance
$c = clone $a; // Create a new copy
var_dump($a, $b, $c);
object(DateTime)#1 (3) {
["date"]=>
string(26) "2020-08-15 19:23:39.016441"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
object(DateTime)#1 (3) {
["date"]=>
string(26) "2020-08-15 19:23:39.016441"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
object(DateTime)#2 (3) {
["date"]=>
string(26) "2020-08-15 19:23:39.016441"
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
Simply put:
first object to be declaredThe behavior is slightly different if one object has been reinitialized (re-assigned) in the course of the script.
Example
class MyClass
{
}
$obj1 = new MyClass;
$obj2 = new stdClass;
$obj3 = new MyClass;
$obj3 = (object) [];
var_dump($obj3);
var_dump($obj1);
var_dump($obj4);
var_dump($obj2);
Result:
object(MyClass)#3 (0) {
}
object(MyClass)#1 (0) {
}
object(stdClass)#4 (0) {
}
object(stdClass)#2 (0) {
}
As you can see, no matter the order of the var_dump, #number tells the order in which the object where instanciated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With