What is the equivalent in PHP for Python's pass statement?

Question:

Do you know any PHP statement that works like Python’s pass statement?

Asked By: Jan Tojnar

||

Answers:

Just leave the bracket’s empty…

Python has the pass word because they don’t use brackets to define the body part of classes, function, and other statement. PHP doesn’t have this dilemma , and therefore doesn’t need something to say that a body statement is empty.

Answered By: Tyler Carter

It isn’t needed in PHP. The Python code:

if x == y:
    pass

Can be written in PHP by just leaving the brackets empty

if ( x == y ){
}

The same applies to other PHP constructs requiring brackets such as classes or functions.

Answered By: Yacoby

Can’t you just use a semicolon?

if ( $x == $y )
  ;
Answered By: rossipedia

When needed for readability you could use

null;
Answered By: ajthinking

The syntax checkers and linters are becoming more and more good at signaling not useful block of codes, also when this is a voluntary action of the developer.

A native do_nothing() function would be very nice and readable sometimes.

To avoid stressing alerts from syntax checkers, I use:

echo(null);
Answered By: TortelliEngineer

NULL is the alternative for pass in python

$a == $b? $b = 10 : NULL;
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.