« PHP 8.3 Manual トップ
著作権 »
per page, with , order by , clip by
Results of 1 - 1 of about 1 for OperatorOverloading (0.001 sec.)
Operator Overloading Magic Methods | PHP 8.3 9414
Operator Overloading Magic Methods The operator overloading extension allows you to define how an object reacts to operators. This is done by implementing the following magic methods: Arithmetic operators: $a::__add($b) $a::__sub($b) $a::__ ... crementing operators: $a::__pre_inc() $a::__post_inc() $a::__pre_dec() $a::__post_dec() String operators: $a::__concat($b) Operator Overloading Examples The following is the class that is used in the testing of the operator overloading extension. It overloads all o ... f the possible operators that can be overloaded for testing. 例1 Complete class for operator overloading <?php class OperatorOverloading { protected mixed $value ; //region Standard magic methods public function __get ( string ... n $this -> value . $val ; } //endregion } Using the above class, you can overload the operators as follows: <?php $a = new OperatorOverloading ( 5 ); var_dump ( $a + 10 ); var_dump ( $a - 10 ); $b = new OperatorOverloading ( "Hello" ); var_dump ( $b . " World" ); T ...
https://man.mtool.work/php/8.3/operator.overloading.html
PREV 1 NEXT