Doc #69811 [Opn]: Cannot bind closure to scope of internal class stdClass

From: Date: Sat, 13 Jun 2015 06:25:21 +0000
Subject: Doc #69811 [Opn]: Cannot bind closure to scope of internal class stdClass
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-12409@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69811&edit=1 ID: 69811 Updated by: kalle@php.net Reported by: olivier dot laviale at gmail dot com Summary: Cannot bind closure to scope of internal class stdClass Status: Open Type: Documentation Problem Package: Documentation problem Operating System: Linux PHP Version: 7.0.0alpha1 Block user comment: N Private report: N New Comment: To clarify Laurence's change; This is intended behaviour that you cannot bind a closure to an class defined internally. Also I think you have a mistake in the example, as you pass a newly created instance of 'A' to the 'A::get_public_vars()' method, but 'A::get_public_vars()' still assumes '$this' in the return statement, not that it would render the practice of binding closures to internally classes anymore allowed ;-) Previous Comments: ------------------------------------------------------------------------ [2015-06-12 12:55:13] olivier dot laviale at gmail dot com Description: ------------ Hi, Looks like the following code is no longer possible with PHP7. The following error is raised: "Cannot bind closure to scope of internal class stdClass". I understand that PHP7 may introduce BC changes, but there's no mention about it in the documentation: http://php.net/manual/en/closure.bind.php Test script: --------------- <?php class A { private $a = 1; protected $b = 2; public $c = 3; static public function get_public_vars() { $get_public_vars = Closure::bind(function($object) { return get_object_vars($object); }, null, 'stdClass'); return $get_public_vars($this); } } var_dump(A::get_public_vars(new A)); Expected result: ---------------- [ 'c' => 3 ] Actual result: -------------- Error: Cannot bind closure to scope of internal class stdClass ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69811&edit=1

« previous php.doc.bugs (#12409) next »