php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #48288 comment above else statment skips it
Submitted: 2009-05-14 23:51 UTC Modified: 2009-05-14 23:58 UTC
From: atomkirk at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: mac osx leopard
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: atomkirk at gmail dot com
New email:
PHP Version: OS:

 

 [2009-05-14 23:51 UTC] atomkirk at gmail dot com
Description:
------------
if you look at the comment "if this child has no other parents besides this one being deleted" right above the else statement.  That comment causes php to skip over the else statement, so both blocks are executed.  I moved that comment below the else statment, and it executes only the block its supposed to.  In other words, it fixes the problem.  I'm no seasoned programmer, but it seems you should be able to place comments there without a problem.

Reproduce code:
---------------
//otherwise, we are deleting the actual record and need to transfer primary children to a secondary parent
	$get_direct_decendants = q("SELECT * FROM dayta_records WHERE parent_record = '$record_id'");
	while($child = mysql_fetch_assoc($get_direct_decendants))
	{
		$child_id = $child['record_id'];
		$get_other_parents = q("SELECT * FROM dayta_parents WHERE record_id = '$child_id'");
		//if this child has another parent, transfer it into its primary
		if(mysql_num_rows($get_other_parents)>0)
		{
			$parent = mysql_fetch_assoc($get_other_parents);
			//get another parent and make it the primary parent record
			$new_parent_id = $parent['parent_id'];
			$update = q("UPDATE dayta_records SET parent_record = '$new_parent_id' WHERE record_id = '$child_id'");
			$delete = q("DELETE FROM dayta_parents WHERE record_id = '$child_id' AND parent_id = '$new_parent_id'");
			//if this child has no other parents besides this one being deleted
		}else{
			//if this child has no other parents besides this one being deleted
			$update = q("UPDATE dayta_records SET parent_record = '0' WHERE record_id = '$child_id'");
			//deleteRecord($child_id);
		}
	}

Expected result:
----------------
should execute only the IF block

Actual result:
--------------
but because of the comment, it executes both IF and ELSE blocks.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-14 23:58 UTC] atomkirk at gmail dot com
not a php problem. a logical problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 10:01:30 2024 UTC