note 88015 modified in language.oop5.typehinting by danbrown

From: Date: Tue, 06 Jan 2009 19:09:18 +0000
Subject: note 88015 modified in language.oop5.typehinting by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148898@lists.php.net to get a copy of this message
Daniel's typehint implementation was just what I was looking for but performance in production wasn't going to cut it. Calling a backtrace every time hurts performance. For my implementation I didn't use it, after all, PHP tells us what the data type is in the error message, I don't feel I need to evaluate the argument where I am using typehinting. Here is the cut down version I use in my error handling class: <?php public static function typehint($level, $message) { if($level == E_RECOVERABLE_ERROR) { if(preg_match('/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/', $message, $match)) { if($match[4] == $match[5]) return true; } } return false; } ?> Hope this can be of use to somebody. --was-- Daniel's typehint implementation was just what I was looking for but performance in production wasn't going to cut it. Calling a backtrace every time hurts performance. For my implementation I didn't use it, after all, PHP tells us what the data type is in the error message, I don't feel I need to evaluate the argument where I am using typehinting. Here is the cut down version I use in my error handling class: <? public static function typehint($level, $message) { if($level == E_RECOVERABLE_ERROR) { if(preg_match('/^Argument (\d)+ passed to (?:(\w+)::)?(\w+)\(\) must be an instance of (\w+), (\w+) given/', $message, $match)) { if($match[4] == $match[5]) return true; } } return false; } ?> Hope this can be of use to somebody. http://php.net/manual/en/language.oop5.typehinting.php

« previous php.notes (#148898) next »