Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong or not precise documentation of magic __get and __set methods in section Handling Business Logic #1568

Closed
hwiesmann opened this issue Dec 1, 2018 · 1 comment

Comments

@hwiesmann
Copy link

hwiesmann commented Dec 1, 2018


name: Bug report
about: The documentation in section "Handling Business Logic" may lead to the impression that under all circumstances the magic methods __get and __set make sure that the PascalCase getXXX and setXXX methods are called. This is not true.


Describe the bug
The documentation says

For each one, the class expects the snake_case column name to be converted into PascalCase, and prefixed with either set or get. These methods will then be automatically called whenever you set or retrieve the class property using the direct syntax (i.e. $user->email).

Unfortunately this is not true. The PHP manual says:

__set() is run when writing data to inaccessible properties. __get() is utilized for reading data from inaccessible properties.

So, whenever you do an assignment to the properties within class methods the magic setters and getters are not called. When the properties are protected also methods of derived classes will not make use of __get or __set.

This also means that the supplied example setCreatedAt is useless because this method is not called internally when modifying the created_at property.

CodeIgniter 4 version
CodeIgniter 4.0.0 Alpha 2 release

Affected module(s)
Entity

@lonnieezell
Copy link
Member

Thanks. Have added a note to clarify that situation.

As for the setCreatedAt method - it is still valid. When the entity is created and data dumped in from the Model, that method would be called, and would convert the date to a Time instance that can be used by the developer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants