|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-05-03 11:34 UTC] m dot cappelleri at xaos dot it
Description:
------------
In a try and catch syntax,
when an Exception is thrown a variable strangely disappears.
Reproduce code:
---------------
$this->_images = array();
while ($r = $q->fetchRow()){
try {
$tmp = NULL;
echo "Adding element ... <br/>";
$tmp = Attachment::Attachment($r['attachment_id'], $r['type_id']);
if (!isNull($tmp)) {
$this->_images[] = $tmp;
}
} catch (xException $e) {
echo "<b>EX</b>";
}
}
echo "<pre>Ora lo printo...";
print_r($this->_images);
echo "</pre>";
Expected result:
----------------
$this->_images SHOULD ALWAYS be an array, no matter when or if an exception is thrown.
Actual result:
--------------
In this case when the exception is thrown in the last cycle the print_r gives a null result.
Even more strangely, $this->_images is still there and correctly populated when requested after that (from a different method).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 07:00:02 2025 UTC |
Sorry, the code example was already a workaround, the code that generates the error is: $this->_images = array(); while ($r = $q->fetchRow()){ try { echo "Adding element ... <br/>"; $this->_images[] = Attachment::Attachment($r['attachment_id'], $r['type_id']); } catch (xException $e) { echo "<b>EX</b>"; } } echo "<pre>Ora lo printo..."; print_r($this->_images); echo "</pre>"; Sorry about that.