<?php
function bool2str($bool)
{
if ($bool === false) {
return 'FALSE';
} else {
return 'TRUE';
}
}
function compareObjects(&$o1, &$o2)
{
echo 'o1 == o2 : ' . bool2str($obj1->equals($obj2)) . "\n";
echo 'o1 != o2 : ' . bool2str($obj1 instanceof $obj2) . "\n";
}
class Flag
{
public $flag;
function Flag($flag = true) {
$this->flag = $flag;
}
}
class OtherFlag
{
public $flag;
function OtherFlag($flag = true) {
$this->flag = $flag;
}
}
$o = new Flag();
$p = new Flag();
$q = $o;
$r = new OtherFlag();
echo "Два экземпляра одного и того же класса\n";
compareObjects($o, $p);
echo "\nДве ссылки на один и тот же экземпляр\n";
compareObjects($o, $q);
echo "\nЭкземпляры двух разных классов\n";
compareObjects($o, $r);
Два экземпляра одного и того же класса
Warning: Undefined variable $obj1 in /in/PA16c on line 13
Fatal error: Uncaught Error: Call to a member function equals() on null in /in/PA16c:13
Stack trace:
#0 /in/PA16c(41): compareObjects(Object(Flag), Object(Flag))
#1 {main}
thrown in /in/PA16c on line 13
Process exited with code 255.
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Flag has a deprecated constructor in /in/PA16c on line 17
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OtherFlag has a deprecated constructor in /in/PA16c on line 26
Два экземпляра одного и того же класса
Notice: Undefined variable: obj1 in /in/PA16c on line 13
Fatal error: Uncaught Error: Call to a member function equals() on null in /in/PA16c:13
Stack trace:
#0 /in/PA16c(41): compareObjects(Object(Flag), Object(Flag))
#1 {main}
thrown in /in/PA16c on line 13
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Два экземпляра одного и того же класса
Fatal error: Uncaught Error: Call to a member function equals() on null in /in/PA16c:13
Stack trace:
#0 /in/PA16c(41): compareObjects(Object(Flag), Object(Flag))
#1 {main}
thrown in /in/PA16c on line 13
Process exited with code 255.
Output for 7.0.0 - 7.0.4
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Flag has a deprecated constructor in /in/PA16c on line 17
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; OtherFlag has a deprecated constructor in /in/PA16c on line 26
Два экземпляра одного и того же класса
Notice: Undefined variable: obj1 in /in/PA16c on line 13
Fatal error: Uncaught Error: Call to a member function equals() on unknown in /in/PA16c:13
Stack trace:
#0 /in/PA16c(41): compareObjects(Object(Flag), Object(Flag))
#1 {main}
thrown in /in/PA16c on line 13
Process exited with code 255.
Output for 5.6.7 - 5.6.28
Два экземпляра одного и того же класса
Notice: Undefined variable: obj1 in /in/PA16c on line 13
Fatal error: Call to a member function equals() on null in /in/PA16c on line 13
Process exited with code 255.
Два экземпляра одного и того же класса
Notice: Undefined variable: obj1 in /in/PA16c on line 13
Fatal error: Call to a member function equals() on a non-object in /in/PA16c on line 13
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Два экземпляра одного и того же класса
Notice: Undefined variable: obj1 in /in/PA16c on line 13
Fatal error: Call to a member function equals() on a non-object in /in/PA16c on line 13
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/PA16c on line 14
Process exited with code 255.