Skip to content

Fix fatal error when using PHP 8.1+ union/intersection types in ACL callbacks and Model Binder#16856

Merged
niden merged 7 commits into5.0.xfrom
copilot/fix-deprecated-reflectionmethod
Mar 24, 2026
Merged

Fix fatal error when using PHP 8.1+ union/intersection types in ACL callbacks and Model Binder#16856
niden merged 7 commits into5.0.xfrom
copilot/fix-deprecated-reflectionmethod

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

ReflectionParameter::getClass() was deprecated in PHP 8.0 and both Acl\Adapter\Memory and Mvc\Model\Binder were already updated to use getType(). However, getType() in PHP 8.0+ can return ReflectionUnionType or ReflectionIntersectionType, neither of which has a getName() method — causing a fatal error when union or intersection types appear in ACL callbacks or controller action parameters.

// Previously caused a fatal error in isAllowed()
$acl->allow('Admin', 'User', ['update'], function (int|string $parameter) {
    return $parameter === 1;
});
$acl->isAllowed('Admin', 'User', 'update', ['parameter' => 1]);

// Also affected Model\Binder when action parameters used union types
public function indexAction(MyModel|null $model) { ... }

Changes

  • Acl/Adapter/Memory.zep: Add use ReflectionNamedType and guard getName() call with instanceof ReflectionNamedType check. Union/intersection type parameters fall through to the user-supplied parameters array as before.
  • Mvc/Model/Binder.zep: Add use ReflectionNamedType and skip model binding (continue) for non-named types — correct behavior since we cannot determine which model class to bind for a union type.
  • tests/unit/Acl/Adapter/Memory/IsAllowedCest.php: Add test verifying union type parameters in ACL callbacks work without fatal errors.
  • CHANGELOG-5.0.md: Entry added to the unreleased 5.11.0 version section.

Thanks

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG]: Method ReflectionParameter::getClass() is deprecated</issue_title>
<issue_description>Sorry for not using the template.

I'm upgrading my project from phalcon 4 (php 7.4) to phalcon 5 (php 8.1) and I'm getting this deprecation message
Method ReflectionParameter::getClass() is deprecated in ....

I checked my code and I'm not using the reflection, I also checked the dependencies, then I dug into phalcon code and I found the following line in phalcon/Acl/Adapter/Memory.zep:705:
let reflectionClass = reflectionParameter->getClass(),.

ReflectionParameter::getClass with some other reflection methods have been deprecated since php 8: https://www.php.net/manual/en/reflectionparameter.getclass.php

Is that something you are aware of?

I forgot, I call AclList::isAllowed at the line I have the deprecation message.</issue_description>

<agent_instructions>Please find the instances in the code and propose fixes</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@niden Thanks for the report. I will take a look at this as soon as I can. @niden This has been resolved in https://github.com//pull/16257 @niden Hello,

Phalcon\Mvc\Model\Binder class seems to have the same problem.

let reflectionClass = methodParam->getClass();</comment_new>


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

@niden niden changed the base branch from master to 5.0.x March 23, 2026 00:38
Copilot AI changed the title [WIP] Fix deprecated ReflectionParameter::getClass method Fix fatal error when using PHP 8.1+ union/intersection types in ACL callbacks and Model Binder Mar 23, 2026
Copilot AI requested a review from niden March 23, 2026 00:39
Copy link
Copy Markdown
Member

@niden niden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the entry in the CHANGELOG-5.0 to the unreleased version

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 23, 2026

Please move the entry in the CHANGELOG-5.0 to the unreleased version

Done — moved the entry to the 5.11.0 unreleased section in commit 2db361b.

Copilot AI requested a review from niden March 23, 2026 02:02
@niden niden marked this pull request as ready for review March 23, 2026 17:04
@niden niden merged commit e277b8d into 5.0.x Mar 24, 2026
26 checks passed
@niden niden deleted the copilot/fix-deprecated-reflectionmethod branch March 24, 2026 23:24
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

Successfully merging this pull request may close these issues.

[BUG]: Method ReflectionParameter::getClass() is deprecated

4 participants