I need the idea of creating an anonymous class in PHP. I do not know how I can work.
See my limitations :
- In PHP, you cannot create an anonymous class, for example an anonymous function (for example,
class {} ); - In PHP, you do not have the scope of the class (except for namespaces, but it has the same problem below);
- In PHP, you cannot use variables to indicate the name of a class (for example,
class $name {} ); - I do not have access to install
runkit PECL.
What do I need and why :
Well, I need to create a function called create_class() that gets the key name and an anonymous class. This will be useful to me because I want to use different characters of the name class that PHP cannot accept. For example:
<?php create_class('it.is.an.example', function() { return class { ... } }); $obj = create_object('it.is.an.example'); ?>
So, I need an idea that allows this use. I need this because in my framework I have this path: /modules/site/_login/models/path/to/model.php . So, model.php needs to declare a new class called site.login/path.to.model .
When create_object() called, if the internal cache has the definition of $class (for example, it.is.an.example ), it simply returns a new class object. If not, download. Therefore, I will use the content of $class to quickly find out what the class file is.
David Rodrigues
source share