Lets imagine that we have following:
class Foo
{
public static $foo;
public static $bar;
public static $baz;
public static $str;
public static $arr;
}
class Bar
{
public static $foo;
public static $bar;
public static $baz;
public static $str;
public static $arr;
}
class Baz
{
public static $foo;
public static $bar;
public static $baz;
public static $str;
public static $arr;
}
Foo::$foo = new Foo();
Bar::$foo = Foo::$foo;
Baz::$foo = Foo::$foo;
Foo::$bar = new Bar();
Bar::$bar = Foo::$bar;
Baz::$bar = Foo::$bar;
Foo::$baz = new Baz();
Bar::$baz = Foo::$baz;
Baz::$baz = Foo::$baz;
Foo::$str = 'cat';
Bar::$str = Foo::$str;
Baz::$str = Foo::$str;
Foo::$arr = [1, 2, 3, 'dog'];
Bar::$arr = Foo::$arr;
Baz::$arr = Foo::$arr;
WHERE:
Foo::$foo
, Bar::$foo
, Baz::$foo
refer same instance of Foo
;
Foo::$bar
, Bar::$bar
, Baz::$bar
refer same instance of Bar
;
Foo::$baz
, Bar::$baz
, Baz::$baz
refer same instance of Baz
;
Foo::$str
, Bar::$str
, Baz::$str
refer same string;
Foo::$arr
, Bar::$arr
, Baz::$arr
refer same array;
Is there any way to identify these values? For instance in C++ I could just use a pointer, which would contain same value for Foo::$foo
, Bar::$foo
and Baz::$foo
.
What is it for?
I have a function which iterates all properties of a given classes and writes property values into common array.
Lets imagine we are iterating over Foo's, Bar's and Baz's properties and adding them into array. In final array we'll have 15 values instead of 5(really different values). If we'll search and compare these values before adding into array then(if `Foo::$str, Bar::$str and BAZ::$str will be not a refs to same value, but just an equal values) we'll have only 5 values instead of 7(3 objects, 1 array and 3 strings).
I hope this edit will help to understand me.
Also:
$a = 1;
$b = &$a;
$c = 1;
($a == $b) // true
($a == $c) // true
In both cases result will be true. But how to know that im comparing 2 references of the same value(2 refs that point same memory address) or im comparing 2 different memory addresses and they they are just equal? It will be helpful for solving this problem.