Make undefined variable an error in php -


i have following code snippet:

<?php ini_set('display_errors', '1'); error_reporting(e_all | e_notice); print $bla; print 7; ?> 

which prints out warning bla undefined, continues afterwards. want php throw error , stop code execution when undefined variable encountered. how that?

the above example. want handle each undefined variable within multi thousand block clode piece.

you write own error handler. , make halt execution when encounter type of notice. take at

http://php.net/manual/en/function.set-error-handler.php

a small , simple example:

function new_error_handler($errno, $errstr, $errfile, $errline) {     switch ($errno) {       case e_notice:         if (strstr($errstr, 'undefined variable')) {           die('undefined variable found');         }       break;     } }  set_error_handler('new_error_handler');  echo $foo; 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -