TypeError when setting database column values using Model->set() #14

Closed
opened 2025-11-30 14:06:55 +01:00 by vlw · 0 comments
vlw commented 2025-11-30 14:06:55 +01:00 (Migrated from codeberg.org)

Trying to set a database column value using the vlw\Scaffold\Database\Model->set() method directly using property hooks in an inheriting class does set the value properly in the database, and the type checking is still working, but it also throws a TypeError since the return type of the set() method is a boolean. It's possible that PHP is also trying to assign the return value to the virtual property itself, although I'm not sure about that.

How to reproduce

Take this virtual property in a class that extends the Model abstract class for example:

final public DateTimeImmutable $date_created {
			get                                   => new DateTimeImmutable($this->get(Fields::DATE_CREATED->value));
			set (DateTimeImmutable $date_created) => $this->set(Fields::DATE_CREATED->value, $date_created->format(Database::DATETIME_FORMAT));
}

Setting it with:

$model->date_created = new DateTimeImmutable();

DOES update the database properly, but also throws:

Exception has occurred: TypeError
Cannot assign true to property Calendar\Database\Models\Fields\Field::$date_created of type DateTimeImmutable
Trying to set a database column value using the `vlw\Scaffold\Database\Model->set()` method directly using property hooks in an inheriting class _does_ set the value properly in the database, and the type checking is still working, but it also throws a `TypeError` since the return type of the `set()` method is a boolean. It's possible that PHP is also trying to assign the return value to the virtual property itself, although I'm not sure about that. # How to reproduce Take this virtual property in a class that extends the `Model` abstract class for example: ```php final public DateTimeImmutable $date_created { get => new DateTimeImmutable($this->get(Fields::DATE_CREATED->value)); set (DateTimeImmutable $date_created) => $this->set(Fields::DATE_CREATED->value, $date_created->format(Database::DATETIME_FORMAT)); } ``` Setting it with: ```php $model->date_created = new DateTimeImmutable(); ``` DOES update the database properly, but also throws: ``` Exception has occurred: TypeError Cannot assign true to property Calendar\Database\Models\Fields\Field::$date_created of type DateTimeImmutable ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
vlw/scaffold#14
No description provided.