note 85527 added to language.oop5.typehinting
| From: | kalkamar at web dot de | Date: | Thu, 04 Sep 2008 09:24:41 +0000 |
| Subject: | note 85527 added to language.oop5.typehinting | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144131@lists.php.net to get a copy of this message | ||
I really like the Daniel`s Typehinting-Class, but you please not that it may be relevant for the
performance if you use Typehinting for scalar values very often.
Here is my performance-test:
<?php
function notypehinting($x)
{
is_string($x); //checking the type manually instead
}
function typehinting(string $x)
{
}
$test=new timer;
for($i=0;$i<10000;$i++)
{
try{
notypehinting('test');
}
catch(Exception $e){}
}
echo $test.'<br>';
$test2=new timer;
for($i=0;$i<10000;$i++)
{
try{
typehinting('test');
}
catch(Exception $e){}
}
echo $test2.'<br>';
?>
Output:
0.0088460445404053
0.21634602546692
Result:
typehinting() ist more than 20 times slower than notypehinting()
You see: typehinting for scalar types (like suggested by Daniel) is not the best thing for the
performance if you use it very often.
----
Server IP: 69.147.83.197
Probable Submitter: 78.53.85.6
----
Manual Page -- http://www.php.net/manual/en/language.oop5.typehinting.php
Edit -- https://master.php.net/note/edit/85527
Del: integrated -- https://master.php.net/note/delete/85527/integrated
Del: useless -- https://master.php.net/note/delete/85527/useless
Del: bad code -- https://master.php.net/note/delete/85527/bad+code
Del: spam -- https://master.php.net/note/delete/85527/spam
Del: non-english -- https://master.php.net/note/delete/85527/non-english
Del: in docs -- https://master.php.net/note/delete/85527/in+docs
Del: other reasons-- https://master.php.net/note/delete/85527
Reject -- https://master.php.net/note/reject/85527
Search -- https://master.php.net/manage/user-notes.php