Skip to content

Instantly share code, notes, and snippets.

@jcupitt
Created February 14, 2022 15:00
Show Gist options
  • Save jcupitt/c43a7a204f0f0c21a108c1d29767de70 to your computer and use it in GitHub Desktop.
Save jcupitt/c43a7a204f0f0c21a108c1d29767de70 to your computer and use it in GitHub Desktop.
You'd think __callStatic() would fire, but I see:
$ ./static.php
calling try_static_call in object context
calling try_static_call in object context
calling try_static_call in object context
calling try_static_call in object context
calling try_method_call in object context
$ php --version
PHP 8.0.8 (cli) (built: Oct 26 2021 11:42:42) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies
#!/usr/bin/php
<?php
class A {
public function __call($name, $arguments) {
echo "calling $name in object context\n";
}
public static function __callStatic($name, $arguments) {
echo "calling $name in static context\n";
}
public function some_method() {
static::try_static_call();
self::try_static_call();
A::try_static_call();
\A::try_static_call();
$this->try_method_call();
}
}
$x = new A();
$x->some_method();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment