Forum Moderators: coopster

Message Too Old, No Replies

PHP 5 error: Creating default object from empty value

         

jackvull

6:24 pm on Jun 20, 2006 (gmt 0)

10+ Year Member



Hi
This code works in PHP4 but for some reason in PHP 5 I get the following fatal error:

() Creating default object from empty value

Code:
// Get the next token in the sequence
for ($i = count($Tokens)-1; $i >= 0 ; $i--){
// Find the position in the string
$start = strpos($thisString, $Tokens[$i]);
// If it's present
if ($start!== false){
// Record position and token name
$resultArray[$i]->start = $start;
$resultArray[$i]->token = $Tokens[$i];
}
}

It says the line causing it is the first $result[$i] line.

Any ideas why?

eelixduppy

6:32 pm on Jun 20, 2006 (gmt 0)



(deleted comment)

jackvull

9:01 pm on Jun 21, 2006 (gmt 0)

10+ Year Member



any ideas what changed in PHP 5?

bcolflesh

9:15 pm on Jun 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try an ampersand in front of that line and the next one, ex:

@$resultArray[$i]->start = $start;

jackvull

11:15 pm on Jun 22, 2006 (gmt 0)

10+ Year Member



Sadly not, still the same error.

coopster

1:42 pm on Jun 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Classes are types, that is, they are blueprints for actual variables. You have to create a variable of the desired type with the new operator.

If the $resultArray[$i] value is not an instance of a class, then I would expect you will indeed get a fatal error. Try var_dump() on that value and see if it is an object.