Req #54066 [Opn->Wfx]: Add possibility to reflect on a file not loaded in memory
| From: | requinix@php.net | Date: | Sat, 05 May 2018 18:34:16 +0000 |
| Subject: | Req #54066 [Opn->Wfx]: Add possibility to reflect on a file not loaded in memory | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-215075@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54066&edit=1
ID: 54066
Updated by: requinix@php.net
Reported by: mathieu at xlsoft dot ca
Summary: Add possibility to reflect on a file not loaded in
memory
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
Package: Reflection related
Operating System: Any
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
Old request is old.
To my knowledge this is non-trivial and would require significant work to implement for a small
number of use cases. Consider also that Reflection allows for many actions that depend upon the code
having been loaded successfully, such as instantiating classes, traversing class hierarchies, and
calling methods. There are userland PHP code parsing libraries out there, even using PHP's own
tokenization functionality, which could be built upon to perform the sorts of validation suggested
in this report.
As such, anyone interested in this feature should talk to the internals mailing list. https://wiki.php.net/rfc/howto
Previous Comments:
------------------------------------------------------------------------
[2011-02-21 21:32:48] mathieu at xlsoft dot ca
Description:
------------
I'd like to see a ReflectionFile class added to the Reflection api that would allow you to
reflect on the content of a file instead of a loaded information.
The reason for this can be varied but in my current case is to reflect the class and code
information inside of a file to display to a user. I'm building a web IDE that will display the
class information of a file in a web project. I don't want to load that file because it could
be a security issue and launch code that i don't want to launch.
Other uses for this is to validate that a file contains a specific class or reflect on the classes
in the file to find if the classes do implement an interface or a specific class without having to
load the code into execution space.
Finaly, if a file contains non encapsulated code that could be executed when including the file,
the ReflectionFile class could be used to detect that and you could refuse using the class file. For
example, a whiz tries to place a statement hidden between two class definitions that could
compromise your application, then you could detect it with:
if($myReflectedFile->hasExecutableStatements()){
//Refuse usage of this file
}else{
include($myReflectedFile->filename);
}
The number of implications for this class are large, they allow many other options such as
documentation extraction from a code file. Many of us are aware that if bytecode caching is active
on a server you won't be able to detect document comments, reading it from the file instead
from the memory could allow many more comment extraction to be possible.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54066&edit=1