aborted
aborted

Reputation: 4541

Reference assignment to a more complex variable

Let's say I have an example like this one:

$foo = 'Hello ';
$bar = 1;

$abc =& $foo . $bar;

if (true) {
    ++$bar;

    if (true)
    {
        ++$bar;
    }
}

echo $abc;

I am expecting $abc to return Hello 3, but it actually returns Hello only. I'm really confused. Is there something I've gotten wrong with references in PHP?

Upvotes: 1

Views: 33

Answers (1)

Nick Rolando
Nick Rolando

Reputation: 26167

A reference variable is like an alias to the same object/variable, and it can only reference one variable at a time.

I'm not really sure how to help your situation because I don't know what you're trying to do, but..

$foo = 'Hello ';
$bar = 1;

$abc =& $bar;

++$bar;
++$bar;

echo $foo . $abc;

http://www.php.net/manual/en/language.references.whatdo.php

Upvotes: 2

Related Questions