<?php
class Dog
{
public static function bark()
{
return 'Woof!';
}
}
echo Dog::bark()."\n"; // method is static, so this is ok
class Cat
{
public function purr() // NOT static
{
return 'purrrrrrrrr';
}
}
echo Cat::purr()."\n"; // will generate deprecation warning
$cat = new Cat();
echo $cat->purr()."\n"; // will work fine
Woof!
Fatal error: Uncaught Error: Non-static method Cat::purr() cannot be called statically in /in/9hdXB:21
Stack trace:
#0 {main}
thrown in /in/9hdXB on line 21
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
Woof!
Fatal error: Uncaught Error: Non-static method Cat::purr() cannot be called statically in /in/9hdXB:21
Stack trace:
#0 {main}
thrown in /in/9hdXB on line 21
Process exited with code 255.