Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Noop

A noop, or no operation, is a command that does nothing. No-op may be an empty expression, or even entirely omitted.

echo an empty string is also a noop: it displays a string, which is empty so has no impact on the output. The entire command may be ignored.

Neutral operations such as + 0 or . '' are noops, but they include a silent cast to integer or string, which may have a larger impact on the other values of the operation.

No operations are often considered as useless. Noops are sometimes needed where an operation is needed, but, contextually, should be neutral.

This is distinct, though close, to the identity: identity returns the incoming data, doing nothing with it. Yet, it still returns something.

<?php

// empty expressions: noops
$a = 1;;;

switch($m) {
    case 1:
     // silent no op here
     // but fallthrough
     
    case 2: 
        $b = 3;
}

while (false);

echo '';

$trunk = 'abc'.'';

'lone string';

?>

Documentation

See Also