What did he mean when he wrote this?

I read a book and the author explains that in PHP variables and properties are created on the fly so if we misspell a name, a new property will be created. So he recommends to set initial value to properties. I don’t get how this recommendation helps? If I call a misspelled property it still will be created, even if I set a value to the original property, So I cant understand what is his point?

“Program design recommendation—Properties are created on the fly in PHP. Properties are created the first time you use them. This can both be a help and a pain. If you misspell a property name, PHP will not produce an error. Instead it will create a new property with the misspelled name. It is recommended (when possible) that properties be created with initial values at the top of your program (or method, or class) to more easily determine what your property name is and whether it has been created.”

If you set public properties in a class then your editor/IDE will auto complete these names for you

vs:


Screenshot276.JPG

Screenshot277.JPG

Sponsor our Newsletter | Privacy Policy | Terms of Service