Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 Internet speed test! ×

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

Consultants are mystical people who ask a company for a number and then give it back to them.

Working...