Skip to content

Bug: PHP 8.5 Deprecation Warning: ReflectionProperty::setAccessible() in CheckQueryReturnTrait #1304

@Scampi-ml

Description

@Scampi-ml

PHP Version

8.5.1

CodeIgniter4 Version

4.6.4

Shield Version

1.2.0

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

MariaDB 10.11

Did you customize Shield?

No

What happened?

WARNING - 2025-12-30 19:50:50 --> [DEPRECATED] Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect since PHP 8.1 in VENDORPATH\codeigniter4\shield\src\Models\CheckQueryReturnTrait.php on line 91. 1 VENDORPATH\codeigniter4\shield\src\Models\CheckQueryReturnTrait.php(81): CodeIgniter\Shield\Models\BaseModel->getPropertyDBDebug() 2 VENDORPATH\codeigniter4\shield\src\Models\CheckQueryReturnTrait.php(29): CodeIgniter\Shield\Models\BaseModel->restoreDBDebug() 3 VENDORPATH\codeigniter4\shield\src\Models\LoginModel.php(87): CodeIgniter\Shield\Models\BaseModel->checkQueryReturn(191) 4 VENDORPATH\codeigniter4\shield\src\Authentication\Authenticators\Session.php(299): CodeIgniter\Shield\Models\LoginModel->recordLoginAttempt('email_password', 'xxxxx@xxxxxx.com', true, 'xxx.xxx.xxx.xxx', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0', 1) 5 VENDORPATH\codeigniter4\shield\src\Authentication\Authenticators\Session.php(176): CodeIgniter\Shield\Authentication\Authenticators\Session->recordLoginAttempt([...], true, 'xxx.xxx.xxx.xxx', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0', 1) 6 VENDORPATH\codeigniter4\shield\src\Controllers\LoginController.php(71): CodeIgniter\Shield\Authentication\Authenticators\Session->attempt([...]) 7 SYSTEMPATH\CodeIgniter.php(933): CodeIgniter\Shield\Controllers\LoginController->loginAction() 8 SYSTEMPATH\CodeIgniter.php(507): CodeIgniter\CodeIgniter->runController(Object(CodeIgniter\Shield\Controllers\LoginController)) 9 SYSTEMPATH\CodeIgniter.php(354): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false) 10 SYSTEMPATH\Boot.php(363): CodeIgniter\CodeIgniter->run() 11 SYSTEMPATH\Boot.php(68): CodeIgniter\Boot::runCodeIgniter(Object(CodeIgniter\CodeIgniter)) 12 FCPATH\index.php(65): CodeIgniter\Boot::bootWeb(Object(Config\Paths))

Steps to Reproduce

  1. Use Shield's default LoginController with Session authenticator
  2. Attempt to log in via LoginController->loginAction()
  3. The warning is triggered during LoginModel->recordLoginAttempt() which calls BaseModel->checkQueryReturn()
  4. The CheckQueryReturnTrait->getPropertyDBDebug() method uses ReflectionProperty::setAccessible() on line 91

Expected Output

No deprecation warnings should appear. The setAccessible() call should be removed as it's unnecessary in PHP 8.1+ (all properties are accessible by default via reflection).

Anything else?

  • This warning appears on every login attempt when using the default Shield login flow
  • The warning is non-fatal but clutters logs and will become an error in future PHP versions
  • The fix should be straightforward: remove the setAccessible() call from CheckQueryReturnTrait.php line 91, as it has no effect in PHP 8.1+

Related Code References

Suggested Fix

Remove the setAccessible() call in CheckQueryReturnTrait.php around line 91, as it's unnecessary in PHP 8.1+:

// Before (deprecated):
$reflection->setAccessible(true);
$value = $reflection->getValue($this);

// After (PHP 8.1+ compatible):
$value = $reflection->getValue($this);### Impact

  • Severity: Low (warning only, not fatal)
  • Frequency: Every login attempt
  • User Impact: None (functionality works correctly)
  • Developer Impact: Log clutter, future compatibility concern

~ Report made with the help of Cursor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions