2

I'm developing an application using php 5.4 and CodeIgniter 2.1 (but I think this is strictly a php questions). I am expecting a pointer to a stdClass to be returned, but instead I receive a null value.

$this->myLittleTest($myLittlePointer);
  // displays "NULL"
echo(gettype($myLittlePointer));
...

function myLittleTest(&$myPtr){
  $myPtr = &$this->myLittleClass->myLittleArrayOfStdClasses[0];
     // displays "object"
  echo(gettype($myPtr));
}

Is there a scope issue causing the pointer to return null? Thanks for your help.

0

1 Answer 1

1

By assigning by reference to a reference, you're breaking the first reference. Just assign to it via =, not =&:

function foo(&$bar) {
    $val = 'baz';
    $bar = $val;
}

foo($bar);
var_dump($bar);

Note that references are not pointers. You are not handing memory address pointers around, PHP does not do that. References just allow you to assign symbol table aliases, nothing more.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! You've solved a long-nagging mystery. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.