Skip to content

PHP 8.6 fixes - #673

Open
andypost wants to merge 2 commits into
phpspec:masterfrom
skilld-labs:php86
Open

PHP 8.6 fixes#673
andypost wants to merge 2 commits into
phpspec:masterfrom
skilld-labs:php86

Conversation

@andypost

@andypost andypost commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #672

Comment on lines 48 to 60
$node->addProperty('objectProphecyClosure', 'private');

foreach ($node->getMethods() as $name => $method) {
if ('__construct' === strtolower($name)) {
$methodName = strtolower($name);

if ('__construct' === $methodName) {
continue;
}

if (!$method->getReturnTypeNode()->hasReturnStatement()) {
if ('__destruct' === $methodName || !$method->getReturnTypeNode()->hasReturnStatement()) {
$method->setCode(
'$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());'
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This does make sense but I was wondering if the special case should be handled at the source. Digging down hasReturnTypeStatement I found its providing some convenience wrapping of BetterReflection's logic. Their issues seem closed and I'm not sure where I'd start with a PR so this is probably a logical fix for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for idea, need to dig it deeper

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

special case should be handled at the source

exactly, PHP 8.6 constructors and destructors are symmetric: neither may return a value, so both must be proxied rather than return-typed so pushing it down will invert deps

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.

PHP 8.6 - Returning a value from a destructor is deprecated

2 participants