Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 505
Jan Tojnar Avatar asked May 17 '10 21:05

Jan Tojnar


People also ask

Does PHP have a pass?

PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists and Named Arguments are also supported.

What can I use instead of pass in Python?

With Python >= 3.0, you should use ... (Ellipsis) instead of pass to indicate "finish later" blocks.

What is pass statement in Python?

Python pass Statement The pass statement is used as a placeholder for future code. When the pass statement is executed, nothing happens, but you avoid getting an error when empty code is not allowed. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.

What is the equivalent of pass in Javascript?

Python's pass mainly exists because in Python whitespace matters within a block. In Javascript, the equivalent would be putting nothing within the block, i.e. {} .


2 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.

like image 91
Tyler Carter Avatar answered Sep 20 '22 01:09

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.

like image 44
Yacoby Avatar answered Sep 21 '22 01:09

Yacoby