Trying to get a non-object property, and similar errors - did the performance fail?

If I have code that causes the above notification and similar, such as an undefined offset for arrays, adding isset() or empty() will test the script's performance improvement in addition to remvoing error notifications?

Edit: just for clarification, I want a bug report, and I know that isset will bypass notifications, this question was about greater performance.

+4
source share
3 answers

First, I assume you have 3 options.

The first disables error_reporting and uses unpunished unknown array offsets:

 error_reporting(0); 

The second uses @ error suppression:

 @$my_array['a']; 

The third uses isset() :

 if (isset($my_array['a'])) { $my_array['a']; } 

I hacked a quick benchmarking script that gives the following results for 1,000,000 executions:

 Turning off error reporting: 6 seconds Using error suppression: 18 seconds Using isset(): 9 seconds 
+5
source

The only thing you need to do is check if your variables are set using isset() , as this will delete your notification. I consider it a good practice to do this if you plan to use any variable that cannot be defined.

In addition, if you do not need the set variable or not, you can also use @ . ( look here if you don't know what @ is)

I don’t think there will be any significant difference in performance (be it micro-optimization, if any), but I believe that in the absence of errors / notifications / warnings, a huge visual improvement will appear.

To hide errors / notifications / warnings, see here .

+1
source

I would say that the biggest performance hit would be in Apache, which writes these errors to a file. Warning generation itself should not be too expensive, but you can check by profiling your code with xdebug or similar to be sure.

+1
source

All Articles