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

Add magic __isset to classes with __get #2219

Closed
MGatner opened this issue Sep 14, 2019 · 2 comments
Closed

Add magic __isset to classes with __get #2219

MGatner opened this issue Sep 14, 2019 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@MGatner
Copy link
Member

MGatner commented Sep 14, 2019

The following classes have a magic __get() method without a corresponding __isset():

  • CodeIgniter4/system/Database/BaseConnection.php
  • CodeIgniter4/system/Model.php
  • CodeIgniter4/system/Session/Session.php
  • CodeIgniter4/system/I18n/Time.php
  • CodeIgniter4/system/CLI/BaseCommand.php
  • CodeIgniter4/system/I18n/TimeDifference.php
  • CodeIgniter4/system/Encryption/Encryption.php
  • CodeIgniter4/system/Encryption/Handlers/BaseHandler.php

In general this is a bad idea because some functions that call language constructs like isset() on an instance will fail to return true when __get() would still return a valid item. See #2205 for one example.

Unless there's some compelling reason not to, I propose each of these classes should have a basic __isset() added, modeled after their __get(). E.g.:

    public function __isset($name)
    {
        return isset($this->attributes[$name]);
    }
@MGatner MGatner added this to the 4.0.0-rc.2 milestone Sep 14, 2019
@MGatner MGatner added the bug Verified issues on the current code behavior or pull requests that will fix them label Sep 14, 2019
@lonnieezell
Copy link
Member

No compelling reason not to do that.

@jim-parry
Copy link
Contributor

Fixed by #2231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

3 participants