<?php
class foo {
private $bar;
public function __construct($bar) {
$this->bar = $bar;
}
public function __toString() {
return $bar;
}
}
$a = new foo('abc');
$b = new foo('ab');
$pos = strpos($a,$b);
Warning: Undefined variable $bar in /in/tnoKs on line 9
Fatal error: Uncaught TypeError: foo::__toString(): Return value must be of type string, null returned in /in/tnoKs:9
Stack trace:
#0 [internal function]: foo->__toString()
#1 /in/tnoKs(15): strpos(Object(foo), Object(foo))
#2 {main}
thrown in /in/tnoKs on line 9
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Warning: Undefined variable $bar in /in/tnoKs on line 9
Fatal error: Uncaught TypeError: foo::__toString(): Return value must be of type string, null returned in /in/tnoKs:9
Stack trace:
#0 [internal function]: foo->__toString()
#1 /in/tnoKs(15): strpos(Object(foo), Object(foo))
#2 {main}
thrown in /in/tnoKs on line 9
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Notice: Undefined variable: bar in /in/tnoKs on line 9
Fatal error: Uncaught Error: Method foo::__toString() must return a string value in /in/tnoKs:15
Stack trace:
#0 /in/tnoKs(15): strpos(Object(foo), Object(foo))
#1 {main}
thrown in /in/tnoKs on line 15
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Recoverable fatal error: Method foo::__toString() must return a string value in /in/tnoKs on line 15
Process exited with code 255.
Notice: Undefined variable: bar in /in/tnoKs on line 9
Recoverable fatal error: Method foo::__toString() must return a string value in /in/tnoKs on line 15
Process exited with code 255.
Notice: Undefined variable: bar in /in/tnoKs on line 9
Catchable fatal error: Method foo::__toString() must return a string value in /in/tnoKs on line 15
Process exited with code 255.