抱歉,標(biāo)題的措辭很奇怪。我希望一個(gè)類有一個(gè)可以查看但不能更改的屬性,并且我想在函數(shù)中設(shè)置它。像這樣:class Foo { public int $bar; public function __construct(int $input) { if ($input < 4) { $this->bar = $input; } }}$foo = new Foo(2);echo $foo->bar; // Returns 2$foo->bar = 1 // Gives error
你能在 PHP 的函數(shù)內(nèi)部設(shè)置一個(gè)常量類屬性嗎?
繁華開(kāi)滿天機(jī)
2023-07-30 13:06:39