Summary of differences between major items such as python and php classes and methods.
Preventing you from knowing which is which.
| item | Python | PHP |
|---|---|---|
| function | def function name(): | function Function name(){} |
| End of processing | new line | ; |
| Comment out | # | // or /* */ |
| variable | Variable name | $Variable name |
| Class definition | class class name: | class class name{} |
| constructor | def __init__(self): | Access right function__construct(){} |
| instance | name of the class() | newname of the class() |
| Property*1 | Property name | $Property name |
| Property call | instance.Property name | instance->Property name |
| Instance itself | self | $this |
| Call own property | self.Property name | $this->Property name |
| Method | def method name(self) | Access right function method name() |
| Method call | instance.Method name() | instance->Method name() |
| Inheritance | class class name(Parent class name): | class class name extends Parent class name{} |
| File reading | import module name | require_once(' ') |
| Class loading | from module name import class name | require_once(' ') |
| Parent class method call | super().Method name() | parent::Method name() |
| Class method | @classmethoddef method name(): |
Access rights static function method name(){} |
| Calling a class method | name of the class.Method name() | name of the class::Method name() |
| Class properties | (In line with the method definition) Property name |
Access rights static$Property name |
| Calling class properties | name of the class.Property name | name of the class::$Property name |
| output | print() | echo/print |
| Array | [] | array() |
| Array with keys | {Key name:value} | array(Key name=>value) |
| Array name with key | Dictionary type | Associative array |
| Number of elements in the array | len(Array) | count(Array) |
| Variable expansion*2 | f'{variable}' | "${variable}" |
| for statement | for variable in range(Open price,closing price,Step) ※closing priceは含まない |
for($Variable name=initial value:Conditional expression:Step){} |
| Extract one by one from the array | for variable in array: | foreach($Variable name as array) |
| if statement | if conditional expression: | if(Conditional expression){} |
| else if | elif conditional expression: | elseif (Conditional expression){} |
| switch statement | None | switch(){case condition:processing; break;} |
| and | and | &&/and |
| or | or | 2 pipes/or |
| Increment operator | None | ++ |
| Decrement operator | None | -- |
| Convert to integer type | int() | intval() |
| Convert to string type | str() | strval() |
| Type conversion to decimal point | float() | floatval() |
| 3-digit separator | '{:,d}'.format(Numerical value) f'{Numerical value:,d}' |
number_format() |
Recommended Posts