diff options
author | Aaron Piotrowski <aaron@trowski.com> | 2015-05-08 00:28:54 -0500 |
---|---|---|
committer | Julien Pauli <jpauli@php.net> | 2015-05-12 13:33:28 +0200 |
commit | 071111ecfc7ba9dabc4dfb2a068744b76540308b (patch) | |
tree | 30af8b1a204dc653ac0a5d12cf3a51cc1d2e1089 /Zend/tests/bug68475.phpt | |
parent | f4d6596283888cb4e30b2feedf626c663b8009ed (diff) | |
download | php-git-071111ecfc7ba9dabc4dfb2a068744b76540308b.tar.gz |
Add support for $callable() sytnax with 'Class::method'
Using the $callable() syntax when used with a string of
the form 'Class::method' would error as an undefined
function, even if the string passed is_callable() or the
callable type-hint. The fix adds support for the $callable()
syntax for any string accepted by is_callable() or the
callable type-hint.
Fix bug 68475 test with deprecated notice
Reduced scope of unit test.
Added tests with arguments.
Diffstat (limited to 'Zend/tests/bug68475.phpt')
-rw-r--r-- | Zend/tests/bug68475.phpt | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Zend/tests/bug68475.phpt b/Zend/tests/bug68475.phpt new file mode 100644 index 0000000000..351edb2e94 --- /dev/null +++ b/Zend/tests/bug68475.phpt @@ -0,0 +1,57 @@ +--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 (EngineException $e) { + echo $e->getMessage() . "\n"; +} + +// Reference undefined class. +$callback = 'UndefinedClass::testMethod'; +try { + $callback(); +} catch (EngineException $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 |