PHP “Assign by reference” oddity

后端 未结 2 508
借酒劲吻你
借酒劲吻你 2021-01-17 07:14

I came across a code snippet which included $a = & $b; but hadn\'t tested whether $b actually existed (if (isset($b))). I wasn\'t sure how PHP

2条回答
  •  遥遥无期
    2021-01-17 07:56

    The slot has to exist for you to be able to alias another variable to it (which is really what's going on here, PHP's "references" aren't really actual things as much as each "by reference" operation is a regular operation with copying replaced by aliasing), but it doesn't have to contain a non-null value, and doesn't until you assign it one (through either of its names).

提交回复
热议问题