What does the variable $this mean in PHP?

前端 未结 10 1756

I see the variable $this in PHP all the time and I have no idea what it\'s used for. I\'ve never personally used it.

Can someone tell me how the variab

10条回答
  •  遥遥无期
    2020-11-22 05:34

    It's a reference to the current object, it's most commonly used in object oriented code.

    • Reference: http://www.php.net/manual/en/language.oop5.basic.php
    • Primer: http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

    Example:

    name = $name;
        }
    };
    
    $jack = new Person('Jack');
    echo $jack->name;
    

    This stores the 'Jack' string as a property of the object created.

提交回复
热议问题