Jump to content

Assigning boolean values to non-objects display no errors?


eldan88

Recommended Posts

Hey guys. I am trying to assign a property in my class to a  true value. What I realized is that when I assign true to the property it doesn't display an error even when calling an object that does not exisit

 

 

for example this would be the correct calling of an object

$validator->delivery_method_session = true;

 

this is the incorrect calling of an object

 

$validatorrrrr ->delivery_method_session = truel

 

When assiging it true to an incorrect calling of an object it doesnt display any error message?? Does any might know why that happens?? Thanks!

Huh? I am not following what you are saying.

 

That is not the "calling" of an object, that is the setting of a property for an object. Plus, you would normally use setter and getter methods for properties.

 

You can create new Objects and Properties on-the-fly - just like when you create a variable using something like:

$foo = 'bar';

You don't have to declare the object and property as you do in some languages. So, by using the wrong object name it is just creating a new object and setting that value to the property name.

 

Turn on error reporting in strict mode and you'll see a warning. Likewise if you were using a setter method you would see an error as well.

error_reporting(E_STRICT);

When using the above error reporting mode, this is the type of error you would receive

 

 

Strict Standards: Creating default object from empty value in C:\xampp\htdocs\test\test.php on line 18

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.