php-src/Zend/tests/bug70685.phpt
Nikita Popov 75af8150f5 Forbid binding methods to incompatible $this
This prohibits binding closures returned by
ReflectionMethod::getClosure() to a $this, which is not an
instance of the method scope. This restriction was already in
place for internal methods, now it is extended to user methods.

ML discussion: http://markmail.org/message/zepnhdyr3kij6di6
2016-04-08 00:38:44 +02:00

23 lines
597 B
PHP

--TEST--
Bug #70685: Segfault for getClosure() internal method rebind with invalid $this
--FILE--
<?php
class cls {}
$c = (new ReflectionMethod('SplStack', 'count'))->getClosure(new SplStack);
$c = $c->bindTo(new cls);
var_dump($c);
$c = (new ReflectionMethod('SplStack', 'count'))->getClosure(new SplStack);
$c = $c->bindTo(new SplStack, 'cls');
var_dump($c);
?>
--EXPECTF--
Warning: Cannot bind method SplDoublyLinkedList::count() to object of class cls in %s on line %d
NULL
Warning: Cannot rebind scope of closure created by ReflectionFunctionAbstract::getClosure() in %s on line %d
NULL