oop - $this variable in PHP -
I have just started acquainting with PHP's OO attributes, and I ask you something about First of all, if the class I'm using in the
$ this
keyword is not defined property variable foo
, then its This means that the following code is being used:
$ this-> Foo = 5; Echo $ this-> Foo;
Will create the foo
property on the runtime, like in JavaScript? What is the visibility of this property?
Yes, this you can easily Can check: php square fu {public function setFoo ($ foo) {$ this- & gt; Foo = $ foo; }} $ F = new Foo (); $ F & gt; SetFoo (5); Echo $ f- & gt; Foo; foo
Will print with 5 errors.
Comments
Post a Comment