List all PHP aliases

In PHP, you can define a class alias using the class_alias function. Is there a way to get a list of all the class aliases defined at runtime?

+6
source share
2 answers

As hek2mgl shows, this is not possible in PHP. Depending on why you want this to be a viable workaround.

I assume that you are trying to detect aliases created in third-party code. You could install the Runkit module , set runkit.internal_override to 1 to enable your own modification of functions, and do something similar in the root file of your project:

 runkit_function_rename('class_alias', 'class_alias_internal'); function class_alias($original, $alias, $autoload = TRUE) { Logsomewhere("Creating alias from $original to $alias!"); class_alias_internal($original, $alias, $autoload); } 

Of course, this also means that you can accurately make up the list you are looking for. I see no runtime use for this function (correct me if I am wrong), so you will only need to do this on the development server as much as necessary. Since Runkit is a rather dangerous module, I would even disable it on devserver as soon as you are done with it.

For other scenarios, similar workarounds may be viable, but I need to know why you are looking for this information. As for PHP, the alias must be undetectable, so it does its job perfectly (to change).

+4
source

Looked at the PHP source code. After registering an alias, PHP does not know what the original is and what the alias is. Like hardlinking in the file system. You can view the code in its latest version here: https://github.com/php/php-src/blob/master/Zend/zend_API.c#L2728

(note that the link may be out of date when you read it. Then search for the function zend_register_class_alias_ex .)

However, a function that displays class table entries that have more than one named reference to it can be created (in the PHP core with C), but it looks like it is not available at the moment.

+4
source

Source: https://habr.com/ru/post/975570/


All Articles