Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Did PHP5 change array references?

Status
Not open for further replies.

thedaver

IS-IT--Management
Jul 12, 2001
2,741
US
I'm moving some scripts from a php4 to a php5 platform.

I'm receiving error messages like:
Notice: Undefined index: 1 in /home/apache.......

I'm referencing the array of values as
Code:
print $matches[1];
which was valid up until today.

I've checked the array and the values are indeed there in their proper positions. But now PHP is complaining that I'm referencing the array incorrectly?

Is there a new method for requesting array elements or is my error reporting level to loose?

Thanks,
D.



D.E.R. Management - IT Project Management Consulting
 
I changed error_reporting to
E_ERROR | E_WARNING | E_PARSE
and the errors went away.

However, I HAVE to ask, what's wrong with referencing the array that way such that PHP bitches about it all!?

D.E.R. Management - IT Project Management Consulting
 
There's nothing wrong with the syntax of the array reference. It's just that PHP is saying there is no element numbered 1 in the array.

Similarly, the script:

Code:
<?php
print '<html><body>';

$a = array ('zero', 'one', 'two');

print $a[0] . '<br>';
print $a[1] . '<br>';
print $a[2] . '<br>';
print $a[3] . '<br>';

print '</body></html>';
?>

produces as output:

[tt]zero
one
two

Notice: Undefined offset: 3 in /home/sites/test/html/test_foo.php on line 9[/tt]



Want the best answers? Ask the best questions! TANSTAAFL!
 
Good post sleipnir214. And thedaver notices and errors are different things. The program continued to function but gave you a notice a sleipnir214 pointed out because part of the array element had no value. Turning off notices is not always neccessary a good thing.
 
Turning off notices is not always neccessary a good thing.
I could not agree more. In a development environment, I strongly recommend that error_reporting be set to E_ALL. That way, you see all the problems with your code, not just the ones that cause it to stop running.



Want the best answers? Ask the best questions! TANSTAAFL!
 
for the record, my intention was not to tell the OP to turn off error reporting, i was merely pointing out that this may have been the issue.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
cLFlaVA:
I, for one, certainly understood that from the beginning.

To be honest, I was suprised when the implemented solution was to adjust error reporting.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top