php / php/doc-en

Outdated or Confusing Information on What References Are Not

Open
#2,740 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

From manual page: https://php.net/language.references.arent


The information on the mentioned page seems outdated or at least very confusing:

<?php
function foo(&$var)
{
    $var =& $GLOBALS["baz"];
}
foo($bar); 
?>

There's no way to bind $bar in the calling scope to something else using the reference mechanism, since $bar is not available in the function foo (it is represented by $var, but $var has only variable contents and not name-to-value binding in the calling symbol table).

You coud just use $GLOBALS["bar"] =& ... Unless I am misunderstanding something, for which I would apoligise, the problem of $bar not being available would only be the case if the defined function would be itself in another function scope. I am also unsure what is meant by

but $var has only variable contents and not name-to-value binding in the calling symbol table

as it is a reference, first to $bar and then to global $baz. This part is probably meant to make the distinction between references and c pointers clear?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the language.references.arent manual page and read the quoted example alongside its explanation. Verify what the example says about references, $bar, $var, and $GLOBALS, then revise the passage so the behavior and terminology are accurate and understandable. Done means the example and surrounding explanation are no longer outdated or confusing.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.