Skip to content

Remove improper uses of references #317

Open
@hemberger

Description

@hemberger

In strict PHP, you can only assign variables by reference. Things
that are not variables include function calls and constants.

So we begin the herculean task of removing all unneeded references.
Here are some important details about references:

  • Objects are always passed/copied by reference (in the c++ sense).
    We can pass an object without the & and still access/modify
    its internal data.

  • Arrays are passed/copied by value, but not really because of
    copy-on-write, which means that it will only make a copy of
    the array if you try to modify it.

  • References disable copy-on-write. If you have an array that was
    copied by value, and then you take a reference to it, you will
    immediately make a copy of it, even if the reference doesn't
    modify that array.

Moral of the story

Do not use references in an attempt to improve performance. PHP
does all the right performance things behind the scenes if
you are using the language in the intended way.

References are only intended for when you truly want to pass
something to another function and have that function modify it.

For more details, see
http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions