Closed sensasi-delight closed 1 year ago
Ada error di
Env/Environment.php
.
di tempatku kok gak error ya bang??
Itu untuk apa dibuat property-nya ya bang?
deprecation notice bang di PHP 8.2 (dynamic property)
deprecation notice bang di PHP 8.2 (dynamic property)
Kita pakai PHP ^8.1 bang, lupa memang ku buat di composer.json
Dan aku juga udah buat __set()
magic method disitu 🤔
Sesuai dengan dokumentasi PHP, "The creation of dynamic properties is deprecated" tetapi yang menggunakan magic method __get()
/__set()
masih tetap bisa seharusnya kalau memang abang pakainya PHP ^8.2
The creation of dynamic properties is deprecated, unless the class opts in by using the #[\AllowDynamicProperties] attribute. stdClass allows dynamic properties. Usage of the __get()/__set() magic methods is not affected by this change.
@theozebua
Kita pakai PHP ^8.1 bang, lupa memang ku buat di
composer.json
udah require php:8.1
aku masukin di https://github.com/theozebua/oze-framework-core/pull/23/commits/cab431365865173b90e190d5be575c1c9ea9080d, sudah aku serve di dua versi PHP gak muncul error bang.
Dan aku juga udah buat
__set()
magic method disitu 🤔 Sesuai dengan dokumentasi PHP, "The creation of dynamic properties is deprecated" tetapi yang menggunakan magic method__get()
/__set()
masih tetap bisa seharusnya kalau memang abang pakainya PHP ^8.2The creation of dynamic properties is deprecated, unless the class opts in by using the #[\AllowDynamicProperties] attribute. stdClass allows dynamic properties. Usage of the __get()/__set() magic methods is not affected by this change.
kayaknya gini bang, __set()
bisa tapi dynamic property di dalam __set()
tetap bakal deprecate bang. contoh:
<?php
class X
{
private int $mililiter;
final public function __set(string $name, mixed $value)
{
if ($name === 'liter') {
$this->mililiter = $value * 1000;
} else {
$this->{$name} = $value;
}
}
}
$x = new X;
$x->liter = 2; // not dynamic 'liter' name is handled on __set()
$x->gallon = 2; // still dynamic because on it will set the `$this->gallon` dynamic prop
echo 'end program';
output on 8.1 and 8.2:
C:\Users\zain\Desktop\oze-framework\public>php81 test.php
end program
C:\Users\zain\Desktop\oze-framework\public>php82 test.php
Deprecated: Creation of dynamic property X::$gallon is deprecated in C:\Users\zain\Desktop\oze-framework\public\test.php on line 12
end program
C:\Users\zain\Desktop\oze-framework\public>
posible solution:
<?php
class X
{
private array $properties;
final public function __set(string $name, mixed $value)
{
$this->properties[$name] = $value;
}
public function __get($name)
{
return $this->properties[$name];
}
}
$x = new X;
$x->liter = 2;
$x->gallon = 2;
echo 'end program';
Aku udah buat query builder-nya ya bang. Tinggal dilanjutkan aja, atau bisa sama-sama kita kerjakan. 😁
Silahkan ke branch feat/query-builder
.
jaga-jaga kalau abang males ngoding 😁