note 104138 modified in language.oop5.magic by danbrown
| From: | danbrown@php.net | Date: | Wed, 25 May 2011 19:30:12 +0000 |
| Subject: | note 104138 modified in language.oop5.magic by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180038@lists.php.net to get a copy of this message | ||
Warning __toString can be triggerd more then one time
<?php
if(strstr(substr($obj,0,1024), 'somestuff')
echo $obj;
return 'missing somestuff at the start, create container!';
substr() will trigger a __toString aswell as echo $obj;
?>
wich cause a performance issue since it will gather all data twice.
what i used as a hotfix:
<?php
__toString(){
if(null === $this->sToString)
$this->sToString = $this->_show();
return $this->sToString;
}
?>
--was--
Warning __toString can be triggerd more then one time
if(strstr(substr($obj,0,1024), 'somestuff')
echo $obj;
return 'missing somestuff at the start, create container!';
substr() will trigger a __toString aswell as echo $obj;
wich cause a performance issue since it will gather all data twice.
what i used as a hotfix:
__toString(){
if(null === $this->sToString)
$this->sToString = $this->_show();
return $this->sToString;
}
http://php.net/manual/en/language.oop5.magic.php