CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

refactor: [BaseConnection] change `@property-read` annotations to just `@property`

Open paulbalandan opened this issue 1 year ago • 3 comments

Description I'm not sure what's the intention of putting these @property-read annotations. Please enlighten me. However, these means the properties are "readonly by annotation", hence they cannot be reassigned later on. But we reassign them in several places across the database connection so I think the intention does not meet the actual practice. Found this because intelephense is complaining of "Cannot modify readonly property ...".

Checklist:

  • [x] Securely signed commits
  • [ ] Component(s) with PHPDoc blocks, only if necessary or adds value
  • [ ] Unit testing, with >80% coverage
  • [ ] User guide updated
  • [x] Conforms to style guide

paulbalandan avatar Jul 22 '24 17:07 paulbalandan

I think these magic properties cannot be written. We cannot write like $db->DBDriver = 'SQLite3', but we can read $db->DBDriver. So they should be @property-read.

The @property-read and @property-write variants MAY be used to indicate "magic" properties that can only be read or written. See https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/property.html

kenjis avatar Jul 23 '24 04:07 kenjis

Okay, I took a look again. These are not magic properties. These are protected properties. But we allow reading their values thru BaseConnection::__get(), that's why we have the annotations.

paulbalandan avatar Jul 23 '24 09:07 paulbalandan

If they are protected properties, they are not readonly. So the "Cannot modify readonly property ..." message is wrong.

kenjis avatar Aug 01 '24 01:08 kenjis