note 88015 deleted from language.oop5.typehinting by nikic
| From: | nikic@php.net | Date: | Sun, 01 Nov 2020 21:48:55 +0000 |
| Subject: | note 88015 deleted from language.oop5.typehinting by nikic | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215687@lists.php.net to get a copy of this message | ||
Note Submitter: bantam at banime dot com
----
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.