Content deleted Content added
Assessment: Computing: class=C (assisted) |
→PHP example - variable variable syntax: new section |
||
Line 321:
Would be nice if all examples could be in one place shown as tabs, like MSDN articles do.
When printing the currently selected/visible one could be printed instead of everything <small class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[Special:Contributions/213.16.221.149|213.16.221.149]] ([[User talk:213.16.221.149|talk]]) 14:54, 4 March 2015 (UTC)</small><!-- Template:Unsigned IP --> <!--Autosigned by SineBot-->
== PHP example - variable variable syntax ==
The PHP example currently contains this section:
<pre>
// With reflection, using variable variables syntax
$className = 'Foo';
$foo = new $className();
$method = 'hello';
$foo->$method();
</pre>
Now, as far as I can see, this method isn't really an example of reflection but it is rather a language feature that allows you to reference a symbol indirectly via a variable. As such it is very similar to taking the approach in Javascript (for example) of using indexing on the global object rather than direct references, e.g. translating `new Foo()` to `new window['Foo']()`. Specific reasons I don't believe this qualifies as reflection:
* It doesn't allow introspection, only indirection.
* You can't get a list of available classes using this technique.
* Given a class name, you can't tell if it exists or not (other than by attempting to create one and catching the exception if that fails).
* Given a class name, you can't get a list of its methods (other than by instantiating it, and examining the resulting object to find out its properties, which you would need to do using an *actual* reflection API, rather than this technique).
I'm therefore not convinced that this example belongs here. It's an interesting hack, and a useful, simple way of creating dynamic behaviour, but due to lacking facilities for introspection, I'm not convinced it's an example of *Reflection*. Opinions? [[User:JulesH|JulesH]] ([[User talk:JulesH|talk]]) 00:39, 22 January 2018 (UTC)
|