1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/dynamic_call/bug68475.phpt
DanielEScherzer bce1f4aeb1 Zend/tests: organize some tests with sub directories (3) (#16444)
First pass at moving `Zend/tests/bug*` tests to existing sub directories

Work towards GH-15631
2025-02-10 00:35:51 +00:00

58 lines
1.3 KiB
PHP

--TEST--
Bug #68475 Calling function using $callable() syntax with strings of form 'Class::method'
--FILE--
<?php
class TestClass
{
public static function staticMethod()
{
echo "Static method called!\n";
}
public static function staticMethodWithArgs($arg1, $arg2, $arg3)
{
printf("Static method called with args: %s, %s, %s\n", $arg1, $arg2, $arg3);
}
}
// Test basic call using Class::method syntax.
$callback = 'TestClass::staticMethod';
$callback();
// Case should not matter.
$callback = 'testclass::staticmethod';
$callback();
$args = ['arg1', 'arg2', 'arg3'];
$callback = 'TestClass::staticMethodWithArgs';
// Test call with args.
$callback($args[0], $args[1], $args[2]);
// Test call with splat operator.
$callback(...$args);
// Reference undefined method.
$callback = 'TestClass::undefinedMethod';
try {
$callback();
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
// Reference undefined class.
$callback = 'UndefinedClass::testMethod';
try {
$callback();
} catch (Error $e) {
echo $e->getMessage() . "\n";
}
?>
--EXPECT--
Static method called!
Static method called!
Static method called with args: arg1, arg2, arg3
Static method called with args: arg1, arg2, arg3
Call to undefined method TestClass::undefinedMethod()
Class "UndefinedClass" not found