Firstly, I know that this question has been repeated here more than once:
But the more I fix all E_NOTICE (as people tell you), the more I notice that:
- I'm micro-optimizing
- I actually do more code and make my code more difficult and slow.
Take an example:
Say that you are using the MongoDB PHP driver, and you have an object MongoDatein the var class with a name tsin the class that represents one row in the collection in your database. Now you access this var as:, $obj->ts->secbut PHP returns a match (E_NOTICE), because tsin this case it is not defined as an object in itself, because this particular line has no field ts. Thus, you think that this is normal, this is the desired behavior, if it is not set to return null, and I will take care of it myself outside the interpreters of my own robotic work (since you wrap this in a function date()that simply returns 1970if var has the value nullor none-object).
, E_NOTICE, , , ANY E_NOTICEs terribad, , . $obj getTs, 3 , , , ts var MongoDate , ...
? PHP , ? , , , PHP null instanceof, ( ), isset() 300 isset() s, - . , , getTs, :
class obj{
public $ts = new MongoDate();
}
ts __constructor ( , , ), ( ).
, , :
- Undefined vars
- (
null vars) - ..
, , , , undefined index none-object? isset() 2 -?
, E_NOTICE , CPU, ... , E_NOTICE, ARE?
,