note 129142 added to class.closure

From: Date: Thu, 04 Jan 2024 20:37:35 +0000
Subject: note 129142 added to class.closure
Groups: php.notes 
Request: Send a blank email to php-notes+get-221096@lists.php.net to get a copy of this message
<?php class A { const APP = 'A_Class.'; public function methodA(){ echo 'methodA.'; } public static function methodStatic(){ echo 'methodStatic.'; } } $otherMethod = function () { echo 'otherMethod.'; $this->methodA(); // $this here is the passed object by Closure::bind or bindTo function echo static::APP; // static here will be the class context of the passed object by Closure::bind or bindTo function echo static::methodStatic(); }; $a = new A(); $newMethod1 = Closure::bind($otherMethod, $a, A::class); $newMethod1(); // Output: otherMethod.methodA.A_Class.methodStatic. $newMethod2 = $otherMethod->bindTo($a, A::class); $newMethod2(); // Output: otherMethod.methodA.A_Class.methodStatic. ?> ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.157.134 (proxied: 109.43.50.37) ---- Manual Page -- https://php.net/manual/en/class.closure.php Edit -- https://main.php.net/note/edit/129142 Del: integrated -- https://main.php.net/note/delete/129142/integrated Del: useless -- https://main.php.net/note/delete/129142/useless Del: bad code -- https://main.php.net/note/delete/129142/bad+code Del: spam -- https://main.php.net/note/delete/129142/spam Del: non-english -- https://main.php.net/note/delete/129142/non-english Del: in docs -- https://main.php.net/note/delete/129142/in+docs Del: other reasons-- https://main.php.net/note/delete/129142 Reject -- https://main.php.net/note/reject/129142 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221096) next »