Can a PHP object instance know its name?

前端 未结 4 715
一向
一向 2021-01-17 16:59

If I have code like this:

class Person {
    $age;
    $height;
    $more_stuff_about_the_person;

    function about() {
        return /* Can I get the per         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 17:55

    Eje211, you're trying to use variables in very bizarre ways. Variables are simply data holders. Your application should never care about the name of the variables, but rather the values contained within them.

    The standard way to accomplish this - as has been mentioned already, is to give the Person class a 'name' property.

    Just to re-iterate, do not rely on variable names to determine the output/functionality of your application.

提交回复
热议问题