From bc1fa9ae5abd634ac3c970c184f98a49f711f7e7 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Mon, 11 Nov 2024 14:24:37 +0000 Subject: [PATCH 1/8] Add stub for ReflectionFunctionAbstract::getClosureCalledClass() --- .../getclosurecalledclass.xml | 122 ++++++++++++++++++ reference/reflection/versions.xml | 1 + 2 files changed, 123 insertions(+) create mode 100644 reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml diff --git a/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml b/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml new file mode 100644 index 000000000000..47d85b99c6a5 --- /dev/null +++ b/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml @@ -0,0 +1,122 @@ + + + + ReflectionFunctionAbstract::getClosureCalledClass + Description + + + + &reftitle.description; + + public ReflectionClassnullReflectionFunctionAbstract::getClosureCalledClass + + + &warn.undocumented.func; + + Description. + + + + + &reftitle.parameters; + &no.function.parameters; + + + &reftitle.returnvalues; + + Description. + + + + + &reftitle.errors; + + When does this function issue E_* level errors, + and/or throw Exceptions. + + + + + &reftitle.changelog; + + + + + &Version; + &Description; + + + + + 8.X.0 + + Description + + + + + + + + + &reftitle.examples; + + <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname> example + + Description. + + + +]]> + + &example.outputs; + + + + + + + + &reftitle.notes; + + + Any notes that don't fit anywhere else should go here. + + + + + + &reftitle.seealso; + + ClassName::otherMethodName + some_function + something appendix + + + + + diff --git a/reference/reflection/versions.xml b/reference/reflection/versions.xml index 642b0ca25e45..43b430c44f28 100644 --- a/reference/reflection/versions.xml +++ b/reference/reflection/versions.xml @@ -27,6 +27,7 @@ + From d2107eea230efa353809a12d947d04690b3b13d8 Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Tue, 12 Nov 2024 19:21:45 +0000 Subject: [PATCH 2/8] Attempt to document methods --- .../getclosurecalledclass.xml | 287 ++++++++++++++---- .../getclosurescopeclass.xml | 34 ++- .../getclosurethis.xml | 26 +- reference/reflection/versions.xml | 2 +- 4 files changed, 277 insertions(+), 72 deletions(-) diff --git a/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml b/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml index 47d85b99c6a5..8e210b7d8337 100644 --- a/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml +++ b/reference/reflection/reflectionfunctionabstract/getclosurecalledclass.xml @@ -1,8 +1,8 @@ - + ReflectionFunctionAbstract::getClosureCalledClass - Description + Returns the class corresponding to $this inside a closure @@ -11,91 +11,266 @@ public ReflectionClassnullReflectionFunctionAbstract::getClosureCalledClass - &warn.undocumented.func; - Description. + Returns the class as a ReflectionClass that + corresponds to $this inside the + Closure. &reftitle.parameters; - &no.function.parameters; + &no.function.parameters; + &reftitle.returnvalues; - Description. - - - - - &reftitle.errors; - - When does this function issue E_* level errors, - and/or throw Exceptions. + Returns a ReflectionClass corresponding to the class + represented by $this in the Closure. + If the function is not a closure or if there was no enclosing class &null; + is returned instead. - - &reftitle.changelog; - - - - - &Version; - &Description; - - - - - 8.X.0 - - Description - - - - - - - - + &reftitle.examples; - - <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname> example - - Description. - + + + Example showcasing difference between + <methodname>ReflectionFunctionAbstract::getClosureCalledClass</methodname>, + <methodname>ReflectionFunctionAbstract::getClosureScopeClass</methodname>, + and <methodname>ReflectionFunctionAbstract::getClosureThis</methodname> + foo(); + } catch (Throwable $e) { + echo $e->getMessage(), PHP_EOL; + } + var_dump(static::class); + try { + static::foo(); + } catch (Throwable $e) { + echo $e->getMessage(), PHP_EOL; + } +}; + +$objects = [ + new A(), + new B(), + new C(), +]; + +foreach ($objects as $newThis) { + foreach ($objects as $newScope) { + echo '$fn is bound to ', $newThis::class, ' with scope ', $newScope::class, PHP_EOL; + $boundFn = $fn->bindTo($newThis, $newScope); + $boundFn(); + $rfn = new ReflectionFunction($boundFn); + echo 'ReflectionFunction($boundFn)->getClosureCalledClass()', PHP_EOL; + var_dump($rfn->getClosureCalledClass()); + echo 'ReflectionFunction($boundFn)->getClosureScopeClass()', PHP_EOL; + var_dump($rfn->getClosureScopeClass()); + echo 'ReflectionFunction($boundFn)->getClosureThis()', PHP_EOL; + var_dump($rfn->getClosureThis()); + } +} + ?> ]]> &example.outputs; getClosureCalledClass() +object(ReflectionClass)#7 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#7 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureThis() +object(A)#2 (0) { +} +$fn is bound to A with scope B +string(1) "A" +Call to private method A::foo() from scope B +string(1) "A" +Call to private method A::foo() from scope B +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#6 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#6 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureThis() +object(A)#2 (0) { +} +$fn is bound to A with scope C +string(1) "A" +Call to private method A::foo() from scope C +string(1) "A" +Call to private method A::foo() from scope C +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#9 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#9 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureThis() +object(A)#2 (0) { +} +$fn is bound to B with scope A +string(1) "B" +success! +string(1) "B" +success! +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#8 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#8 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureThis() +object(B)#3 (0) { +} +$fn is bound to B with scope B +string(1) "B" +Call to private method A::foo() from scope B +string(1) "B" +Call to private method A::foo() from scope B +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#7 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#7 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureThis() +object(B)#3 (0) { +} +$fn is bound to B with scope C +string(1) "B" +Call to private method A::foo() from scope C +string(1) "B" +Call to private method A::foo() from scope C +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#5 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#5 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureThis() +object(B)#3 (0) { +} +$fn is bound to C with scope A +string(1) "C" +success! +string(1) "C" +Call to private method C::foo() from scope A +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#6 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#6 (1) { + ["name"]=> + string(1) "A" +} +ReflectionFunction($boundFn)->getClosureThis() +object(C)#4 (0) { +} +$fn is bound to C with scope B +string(1) "C" +Call to private method C::foo() from scope B +string(1) "C" +Call to private method C::foo() from scope B +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#8 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#8 (1) { + ["name"]=> + string(1) "B" +} +ReflectionFunction($boundFn)->getClosureThis() +object(C)#4 (0) { +} +$fn is bound to C with scope C +string(1) "C" +string(1) "C" +ReflectionFunction($boundFn)->getClosureCalledClass() +object(ReflectionClass)#9 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureScopeClass() +object(ReflectionClass)#9 (1) { + ["name"]=> + string(1) "C" +} +ReflectionFunction($boundFn)->getClosureThis() +object(C)#4 (0) { +} ]]> - - &reftitle.notes; - - - Any notes that don't fit anywhere else should go here. - - - - &reftitle.seealso; - ClassName::otherMethodName - some_function - something appendix + ReflectionFunctionAbstract::getClosureScopeClass + ReflectionFunctionAbstract::getClosureThis + diff --git a/reference/reflection/reflectionfunctionabstract/getclosurescopeclass.xml b/reference/reflection/reflectionfunctionabstract/getclosurescopeclass.xml index e91d25a5e77d..4d7e1f89602a 100644 --- a/reference/reflection/reflectionfunctionabstract/getclosurescopeclass.xml +++ b/reference/reflection/reflectionfunctionabstract/getclosurescopeclass.xml @@ -1,9 +1,9 @@ - + ReflectionFunctionAbstract::getClosureScopeClass - Returns the scope class associated with the closure + Returns the class corresponding to the scope inside a closure @@ -12,10 +12,11 @@ public ReflectionClassnullReflectionFunctionAbstract::getClosureScopeClass - - Get the class enclosing the closure declaration. - - + + Returns the class as a ReflectionClass that + corresponds to the scope inside the + Closure. + @@ -25,11 +26,26 @@ &reftitle.returnvalues; - - Returns the class, or &null; if the function is not a closure or if there was no enclosing class. - + + Returns a ReflectionClass corresponding to the class + whose scope is being used inside the Closure. + If the function is not a closure or if there was no enclosing class &null; + is returned instead. + + + + + + + &reftitle.seealso; + + ReflectionFunctionAbstract::getClosureCalledClass + ReflectionFunctionAbstract::getClosureThis + + + - + ReflectionFunctionAbstract::getClosureThis - Returns this pointer bound to closure + Returns the object which corresponds to $this inside a closure @@ -25,12 +25,26 @@ &reftitle.returnvalues; - - Returns $this pointer. - Returns &null; in case of an error. - + + Return the object instance represented by $this inside + the Closure. + If the function is not a closure or if there was no enclosing class &null; + is returned instead. + + + + + + + &reftitle.seealso; + + ReflectionFunctionAbstract::getClosureCalledClass + ReflectionFunctionAbstract::getClosureScopeClass + + +