PHP 8.6 - Returning a value from a destructor is deprecated

Open Beginner friendly
#672 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
67/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
php
Domain
testing

Research direction

Start by tracing ClassCodeGenerator, focusing on how it emits a doubled class's __destruct method. Verify the generated destructor no longer returns a value and that the resulting double does not trigger the PHP 8.6 deprecation.

Written by the indexing model from the issue text.

Description

When a doubled class specifies a __destruct method, ClassCodeGenerator currently builds

<?php
namespace Double\xxxx {
class P1 extends \xxxx implements \Prophecy\Doubler\DoubleInterface, \Prophecy\Prophecy\ProphecySubjectInterface, \Prophecy\Doubler\Generator\ReflectionInterface {

...

public  function __destruct() {
return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());
}

...

}

and this will throw a deprecation in PHP 8.6.

It's due to PHP RFC: Deprecate returning values from __construct() and __destruct(), that was committed in https://github.com/php/php-src/pull/21982.

Dominant language
PHP
Stars
8.5k
Forks
247
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpspec/prophecy

All issues in phpspec/prophecy

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.