phpspec / phpspec

SpecBDD Framework for PHP
http://www.phpspec.net
Other
1.87k stars 276 forks source link

PHP 8.2 deprecation warning: Creation of dynamic property PhpSpec\Loader\StreamWrapper::$context is deprecated #1434

Closed TysonAndre closed 1 year ago

TysonAndre commented 1 year ago

Internally, https://www.php.net/stream_wrapper_register works by adding a property context to the instance of the StreamWrapper

Adding a declared /** @var resource|null */ public $context; would work around this (or #[\AllowDynamicProperties])

php > class FakeStreamWrapper {}
php > stream_wrapper_register('fake', FakeStreamWrapper::class);
php > file('fake://foo');
Deprecated: Creation of dynamic property FakeStreamWrapper::$context is deprecated in php shell code on line 1
Warning: file(fake://foo): Failed to open stream: "FakeStreamWrapper::stream_open" call failed in php shell code on line 1

When running test suites (e.g. of phpspec/prophecy) with php 8.2, errors such as these are seen (from opening files, which instantiates streamwrapper and adds the dynamic property context)


Deprecated: Creation of dynamic property PhpSpec\Loader\StreamWrapper::$context is deprecated in .../vendor/phpspec/phpspec/src/PhpSpec/Loader/ResourceLoader.php on line 61
Deprecated: Creation of dynamic property PhpSpec\Loader\StreamWrapper::$context is deprecated in .../vendor/phpspec/phpspec/src/PhpSpec/Util/MethodAnalyser.php on line 58
gquemener commented 1 year ago

Fixed by https://github.com/phpspec/phpspec/pull/1435

andypost commented 1 year ago

also it needs to allow 8.2 for composer, otherwise tests wont run

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpspec/prophecy[1.9.0, ..., v1.10.3] require php ^5.3|^7.0 -> your php version (8.2.0-dev) does not satisfy that requirement.
    - phpspec/prophecy[1.11.0, ..., 1.11.1] require php ^7.2 -> your php version (8.2.0-dev) does not satisfy that requirement.
    - phpspec/prophecy[1.12.0, ..., 1.13.0] require php ^7.2 || ~8.0, <8.1 -> your php version (8.2.0-dev) does not satisfy that requirement.
gquemener commented 1 year ago

I have introduced such a change: https://github.com/phpspec/phpspec/pull/1435/files#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R25

andypost commented 1 year ago

I mean the prophecy said it it's not compatible so testing can't run on 8.2

gquemener commented 1 year ago

Yup, I've opened a PR on prophecy to support 8.2, but it also requires phpspec (in dev). So one of those PR must be merged first so that the other starts passing.

andypost commented 1 year ago

It could be closed as https://github.com/phpspec/phpspec/pull/1435 been commited

rogervila commented 1 year ago

Let's wait for a new version to be released with 8.2 support before closing this Issue

rogervila commented 1 year ago

I made a PR to fix CI issues on the main branch (https://github.com/phpspec/phpspec/pull/1437)