php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32923 Try and catch strange behaviour
Submitted: 2005-05-03 11:34 UTC Modified: 2005-05-13 01:00 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: m dot cappelleri at xaos dot it Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.4 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: m dot cappelleri at xaos dot it
New email:
PHP Version: OS:

 

 [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).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-03 11:37 UTC] m dot cappelleri at xaos dot it
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.
 [2005-05-05 20:25 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2005-05-13 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 17:01:37 2024 UTC