Forgot your password?
typodupeerror

Comment Re:Take PHP outside web pages altogether. (Score 1) 292

functionReturningAnObject()->field doesn't work

This works fine in PHP 5.1.4:

class TestClass {
function TestClass()
{
$this->field = 1000;
}
}

function returnAnObject()
{
$obj = new TestClass;
return $obj;
}

echo returnAnObject()->field;
- - - - - - - -

Now, explain to me why it is that the last item in $a is incremented twice, while all the others are only incremented once?

Sure (after some fiddling around). As you enter the second foreach loop, $b contains a reference to the last member of the array because that's how the previous foreach left things. Therefore, for each iteration, what you are saying is this: Make the last member of the array ($a[3] as referenced by $b) equal to the current member of the array, plus one.

If $b added 1 to itself (as might be expected) then the value would end up being 9. What seems to be happening in the second loop is: $a[3] = $a[n] + 1, not $a[3] += 1

I don't know if that behaviour is right or wrong in a formal sense.

Slashdot Top Deals

You must realize that the computer has it in for you. The irrefutable proof of this is that the computer always does what you tell it to do.

Working...