Skip to content

PHP 8.3: deprecate Phar::setStub() #1980

@afilina

Description

@afilina

Related to #1589

Analysis

Recap of existing PHP 8.2 behavior based on the RFC:

class Phar
{
    // Signature 1: called with exactly 1 argument.
    public function setStub(string $string) {}
    
    // Signature 2: called with exactly 2 arguments.
    public function setStub(resource $resource, int $length) {}
}

Updated behavior for each version:

class Phar
{
    // Signature 1: unchanged behavior

    // Signature 2: deprecated in 8.3, removed in a future (TBD) major version.
}

According to the RFC:

Impact analysis: None of the 2000 most popular PHP packages rely on calling Phar::setStub() or PharData::setStub() with a resource argument.

I have independently verified this information.

Detection in PHP 8.2

  • (new Phar(...))->setStub(...) with 2 arguments is valid.

Detection in PHP 8.3

  • (new Phar(...))->setStub(...) with 2 arguments is deprecated, add warning. See "Syntax Variations" below.

Syntax Variations

  • (new Phar(...))->setStub(...) ✅ Can be handled by PHPCompatibility.
  • new Phar(...)->setStub(...) ✅ Can be handled by PHPCompatibility.
  • $phar = new Phar(...); $phar->setStub(...); 🤷‍♀️ If they immediately follow each other, then maybe, but of limited value.
  • $phar->setStub(...); ❌ Unreliable, as $phar could be defined anywhere or reassigned before reaching this statement.

Note: top 2000 packages don't use the deprecated signature.

3v4l.org

The Phar extension is not available on 3v4l.org

References

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions