<?php
// If the symbol tables were merged, all these would become theoretically possible:
function f(callable $f) { }
function FuncName() { }
class ClassName
{
public $PropName;
function MethodName() {}
}
f(FuncName); // currently looks for a constant
f(ClassName::MethodName); // currently looks for a class constant
$o = new ClassName;
f($o->MethodName); // currently looks for a property
$o->PropName = function() {};
$o->PropName(); // currently tries to invoke a method
// ================================
// Additionally, the ability to pass func/method ptrs around as first-class symbols would allow such references to
// implicitly be bound to the scope where the reference was defined, eliminating this problem
class Scope
{
public $callbacks = [];
public function registerCallback(callable $f) { $this->callbacks[] = $f; }
private function inner() {}
public function __construct()
{
// works, inner() is accessible from this scope so the `callable` constraint is satisfied
$this->registerCallback([$this, 'inner']);
}
}
$o = new Scope();
($o->callbacks[0])(); // scope error, despite the theoretically type-safe way that the callback was added
Fatal error: Uncaught Error: Undefined constant "FuncName" in /in/2GMh8:15
Stack trace:
#0 {main}
thrown in /in/2GMh8 on line 15
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
Fatal error: Uncaught Error: Undefined constant "FuncName" in /in/2GMh8:15
Stack trace:
#0 {main}
thrown in /in/2GMh8 on line 15
Process exited with code 255.
Warning: Use of undefined constant FuncName - assumed 'FuncName' (this will throw an Error in a future version of PHP) in /in/2GMh8 on line 15
Fatal error: Uncaught Error: Undefined class constant 'MethodName' in /in/2GMh8:17
Stack trace:
#0 {main}
thrown in /in/2GMh8 on line 17
Process exited with code 255.
Output for 7.1.25 - 7.1.33
Notice: Use of undefined constant FuncName - assumed 'FuncName' in /in/2GMh8 on line 15
Fatal error: Uncaught Error: Undefined class constant 'MethodName' in /in/2GMh8:17
Stack trace:
#0 {main}
thrown in /in/2GMh8 on line 17
Process exited with code 255.