class - PHP show names of all declared classes? -


Say I have this code:

  & lt ;? Php square hello {var $ greeting = "hello"; Function Hello () {echo $ this-> Greeting; Return; }} $ Hello1 = New Hello; $ Hello 2 = new hello; $ Hello = 4 hello; ? & Gt;  

How can I get it to echo all the names of objects (and if possible, their respective classes) so that it echos (possibly in an array) "Hello 1 => Hello, Hello 2 => Hello, Hello 4 => Hello ".

If this is not possible, there is no way to exclude the example name from the class like echo example_name ($ this); I will get "Hello 1" Thanks.

To get an array of all the objects, call get_defined_vars Use get_class to get the square name for each code, and then (code has not been tested, but it should work):

  $ vars = array (); Forex Currency (get_defined_vars () as $$) {$ vars [$ var] = get_class ($ var); }  

FII, which you call "declared class" is more famous as "object".

Your second question is not possible. For example, take:

  $ hello1 = $ hello2 = new hello ();  

Now, if I call example_name , should it return 'Hello1' or 'Hello2'?


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -