<?php
var_dump(1 + 1); // int 2
var_dump('1' + '1'); //int 2
class One {
public function __toString() {
return '1';
}
}
var_dump(new One + new One); // Object of class One could not be converted to int int 2
var_dump((string)new One + (string)new One); // int 2
var_dump(2 + 2); // int 4
var_dump('2' + '2'); // int 4
class Two {
public function __toString() {
return '2';
}
}
var_dump(new Two + new Two); // Notice: Object of class Two could not be converted to int int 2
var_dump((string)new Two + (string)new Two); // int 4
int(2)
int(2)
Fatal error: Uncaught TypeError: Unsupported operand types: One + One in /in/OHQqq:12
Stack trace:
#0 {main}
thrown in /in/OHQqq on line 12
Process exited with code 255.
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
int(2)
int(2)
Notice: Object of class One could not be converted to number in /in/OHQqq on line 12
Notice: Object of class One could not be converted to number in /in/OHQqq on line 12
int(2)
int(2)
int(4)
int(4)
Notice: Object of class Two could not be converted to number in /in/OHQqq on line 25
Notice: Object of class Two could not be converted to number in /in/OHQqq on line 25
int(2)
int(4)
int(2)
int(2)
Notice: Object of class One could not be converted to int in /in/OHQqq on line 12
Notice: Object of class One could not be converted to int in /in/OHQqq on line 12
int(2)
int(2)
int(4)
int(4)
Notice: Object of class Two could not be converted to int in /in/OHQqq on line 25
Notice: Object of class Two could not be converted to int in /in/OHQqq on line 25
int(2)
int(4)
Output for 5.1.1 - 5.1.6
int(2)
int(2)
Notice: Object of class One could not be converted to int in /in/OHQqq on line 12
Notice: Object of class One could not be converted to int in /in/OHQqq on line 12
int(2)
int(0)
int(4)
int(4)
Notice: Object of class Two could not be converted to int in /in/OHQqq on line 25
Notice: Object of class Two could not be converted to int in /in/OHQqq on line 25
int(2)
int(0)
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/OHQqq on line 26
Process exited with code 255.
Output for 5.0.0 - 5.0.5
int(2)
int(2)
Fatal error: Unsupported operand types in /in/OHQqq on line 12
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OHQqq on line 7
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OHQqq on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/OHQqq on line 7
Process exited with code 255.