Created
May 7, 2020 16:10
-
-
Save SebSept/38d23301be75a134ee27e0eb850a5025 to your computer and use it in GitHub Desktop.
immutable, not hackable by the __construct()
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 | |
class imu | |
{ | |
/** | |
* @var float | |
*/ | |
private $one; | |
/** | |
* @var float | |
*/ | |
private $two; | |
private function __construct(float $one, float $two) | |
{ | |
$this->one = $one; | |
$this->two = $two; | |
} | |
public static function createFromFloats(float $one, float $two): self | |
{ | |
return new static($one, $two); | |
} | |
public function __toString() | |
{ | |
return sprintf("one : %f & two : %f", $this->one, $this->two); | |
} | |
} | |
$imu = imu::createFromFloats(5.0, 0.0); | |
echo $imu; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
final class imu
serait mieux.