-
-
Save HillLiu/fa84bc3327cdccc248c5484f4df05755 to your computer and use it in GitHub Desktop.
Dirty Mixed PHP7 & PHP8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
/** | |
* PHP8 | |
* add : https://php.watch/versions/8.0/union-types | |
*/ | |
class SimpleMath | |
{ | |
#[PHP8] private int|float $inline_num; /* | |
private $inline_num; /* PHP<8 */ | |
#[PHP8] public function setNum(int|float $num=8): void { /* | |
public function setNum($num=7): void { /* PHP<8 */ | |
$this->inline_num = $num; | |
} | |
#[PHP8] public function squareAndAdd(int|float $num): int|float { /* | |
public function squareAndAdd($num) { /* PHP<8 */ | |
return $num ** 2 + $this->inline_num; | |
} | |
} | |
$simple = new SimpleMath(); | |
$simple->setNum(); | |
echo $simple->squareAndAdd(1.2) . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment