Documentation

PassableByReferencePass extends CodeCleanerPass
in package

Validate that only variables (and variable-like things) are passed by reference.

Table of Contents

EXCEPTION_MESSAGE  = 'Only variables can be passed by reference'
afterTraverse()  : null|array<string|int, Node>
Called once after traversal.
beforeTraverse()  : null|array<string|int, Node>
Called once before traversal.
enterNode()  : mixed
leaveNode()  : null|int|Node|array<string|int, Node>
Called when leaving a node.
isPassableByReference()  : mixed
validateArrayMultisort()  : mixed
Because array_multisort has a problematic signature... The argument order is all sorts of wonky, and whether something is passed by reference or not depends on the values of the two arguments before it.

Constants

Methods

afterTraverse()

Called once after traversal.

public afterTraverse(array<string|int, mixed> $nodes) : null|array<string|int, Node>

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, mixed>

Array of nodes

Return values
null|array<string|int, Node>

Array of nodes

beforeTraverse()

Called once before traversal.

public beforeTraverse(array<string|int, mixed> $nodes) : null|array<string|int, Node>

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, mixed>

Array of nodes

Return values
null|array<string|int, Node>

Array of nodes

leaveNode()

Called when leaving a node.

public leaveNode(Node $node) : null|int|Node|array<string|int, Node>

Return value semantics:

  • null => $node stays as-is
  • NodeTraverser::REMOVE_NODE => $node is removed from the parent array
  • NodeTraverser::STOP_TRAVERSAL => Traversal is aborted. $node stays as-is
  • array (of Nodes) => The return value is merged into the parent array (at the position of the $node)
  • otherwise => $node is set to the return value
Parameters
$node : Node

Node

Return values
null|int|Node|array<string|int, Node>

Replacement node (or special return value)

validateArrayMultisort()

Because array_multisort has a problematic signature... The argument order is all sorts of wonky, and whether something is passed by reference or not depends on the values of the two arguments before it.

private validateArrayMultisort(Node $node) : mixed

We'll do a good faith attempt at validating this, but err on the side of permissive.

This is why you don't design languages where core code and extensions can implement APIs that wouldn't be possible in userland code.

Parameters
$node : Node
Tags
throws
FatalErrorException

for clearly invalid arguments

Return values
mixed

Search results