php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55836 main()-warning
Submitted: 2011-10-03 13:44 UTC Modified: 2016-08-07 04:22 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:4 (100.0%)
Same OS:4 (100.0%)
From: keyboard27 dot 10 at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: SimpleXML related
PHP Version: 5.3.1 OS: Windows 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: keyboard27 dot 10 at gmail dot com
New email:
PHP Version: OS:

 

 [2011-10-03 13:44 UTC] keyboard27 dot 10 at gmail dot com
Description:
------------
"Warning: main() [function.main]: Cannot add element <XML-element-name> number 1 when only 0 such elements exist"
I get this error when trying to read from an xml-file.
In the file i need to jump to a parent-element from a child-element.
//Code:
if((int)$Verse_ID >= sizeof($Chap->Verse))
{
	if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))
	{
		if((int)$Book_ID == sizeof($xml_Books->Book))
		{
			$Book_ID = 1;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
		else
		{
			$Book_ID++;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
	}
	else
	{
		$Chap_ID++;
		$Verse_ID = 1;
	}
}
else
{
	$Verse_ID++;
}
//$Chap, $xml_Books and $Book are xml-nodes

Test script:
---------------
//Code:
if((int)$Verse_ID >= sizeof($Chap->Verse))
{
	if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))
	{
		if((int)$Book_ID == sizeof($xml_Books->Book))
		{
			$Book_ID = 1;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
		else
		{
			$Book_ID++;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
	}
	else
	{
		$Chap_ID++;
		$Verse_ID = 1;
	}
}
else
{
	$Verse_ID++;
}
//$Chap, $xml_Books and $Book are xml-nodes


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-03 13:45 UTC] keyboard27 dot 10 at gmail dot com
-PHP Version: Irrelevant +PHP Version: 5.3.1
 [2011-10-03 13:45 UTC] keyboard27 dot 10 at gmail dot com
Sorry for the double code...
 [2011-10-03 13:47 UTC] keyboard27 dot 10 at gmail dot com
the actual warning comes from the following line:
"if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))"
 [2011-10-03 14:10 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-10-03 14:10 UTC] pajoye@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 the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2011-10-03 14:16 UTC] keyboard27 dot 10 at gmail dot com
-Status: Feedback +Status: Open
 [2011-10-03 14:16 UTC] keyboard27 dot 10 at gmail dot com
is it oke if i would send you the files?
the one is the xml-file which the other file reads and partly displays
it is in dutch, but that shouldn't be a problem

the $Boek_ID var has the value 2, $Hfst_ID is 1 and $Vers_ID is 22, which is Exodus(book #2) 1:22
 [2011-11-26 11:16 UTC] keyboard27 dot 10 at gmail dot com
<?php
//$Verse_ID = 22 (retrieved from database)
//$Chap_ID = 1 (retrieved from database)
//$Book_ID = 2 (retrieved from database)
//$Chap = XML Node
//$Chap->Verse = xml node array(size: 22)
//$Book = xml node array(size: 66)
//$book[($book_id-1)] = xml node array(size: 40)
//$xml_books = xml node
//$xml_books->book = xml node array(size:66)
if((int)$Verse_ID >= sizeof($Chap->Verse))
{
	if((int)$Chap_ID >= sizeof($Book[($Book_ID-1)]))
	{
		if((int)$Book_ID == sizeof($xml_Books->Book))
		{
			$Book_ID = 1;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
		else
		{
			$Book_ID++;
			$Chap_ID = 1;
			$Verse_ID = 1;
		}
	}
	else
	{
		$Chap_ID++;
		$Verse_ID = 1;
	}
}
else
{
	$Verse_ID++;
}
?>
 [2016-07-25 10:21 UTC] cmb@php.net
-Status: Open +Status: Feedback -Package: Unknown/Other Function +Package: SimpleXML related -Assigned To: +Assigned To: cmb
 [2016-07-25 10:21 UTC] cmb@php.net
Does this issue still persist with currently supported PHP
versions? If so, please reopen, and provide a self-contained
reproduce script. If you can't minimize the reproduce script,
please make it available for download.
 [2016-08-07 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 14 20:01:26 2024 UTC