note 94692 deleted from language.oop5.typehinting by danbrown
| From: | danbrown@php.net | Date: | Wed, 18 Nov 2009 21:36:41 +0000 |
| Subject: | note 94692 deleted from language.oop5.typehinting by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163045@lists.php.net to get a copy of this message | ||
Note Submitter: Theriault
----
To get a slightly better performance using Bantam's version of Daniel's idea, one can
switch to strpos instead of using preg_match.
<?php
public static function typehint($level, $message) {
if($level == E_RECOVERABLE_ERROR) {
$Pos = strpos($message, 'must be an instance of ', 24);
if ($Pos !== false) {
$Pos += 23;
$Type1 = strpos($message, ',', $Pos);
if ($Type1 !== false) {
$Type1 += 2;
$Type2 = strpos($message, 'given,', $Type1);
if ($Type2 !== false) {
$TypeA = substr($Msg, $Pos, $Type1 - $Pos - 2);
$TypeB = substr($Msg, $Type1, $Type2 - $Type1 - 1);
if ($TypeA === $TypeB) {
return true;
}
}
}
}
}
return false;
}
?>