Created
August 25, 2012 02:14
-
-
Save felipelavinz/3458853 to your computer and use it in GitHub Desktop.
Deprecated functions exception handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// versión re-escrita | |
function array_to_object($array = array()) { | |
try { | |
throw new flv_exception_deprecated( __FUNCTION__ ); | |
} catch ( flv_exception_deprecated $e ) { | |
flv_handle_exceptions( $e ); | |
return (object)$array; | |
} | |
} | |
// versión anterior del código :-P | |
/*function array_to_object($array = array()) { | |
if (!empty($array)) { | |
$data = false; | |
foreach ($array as $akey => $aval) { | |
$data->{$akey} = $aval; | |
} | |
return $data; | |
} | |
return false; | |
}*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class flv_exception_deprecated extends Exception{ | |
protected $replacement; | |
function __construct( $function, $replacement = '' ){ | |
$this->message = trim($function); | |
if ( $replacement ) $this->replacement = $replacement; | |
parent::__construct(); | |
} | |
function getReplacement(){ | |
return $this->replacement; | |
} | |
function __toString(){ | |
$out = 'DEPRECATED function: '. $this->getMessage() .' on '. $this->getFile() .':'. $this->getLine(); | |
$replacement = $this->getReplacement(); | |
return $replacement ? $out . '. Please use '. $this->getReplacement() .' instead.' : $out; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function flv_handle_exceptions( $e ){ | |
if ( WP_DEBUG ) { | |
error_log( $e ."\n". $e->getTraceAsString() ); | |
} | |
return; | |
} | |
set_exception_handler('flv_handle_exceptions'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment