protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Creation of dynamic property is deprecated in PHP 8.2

Open stanislav-janu opened this issue 3 years ago • 6 comments

Please change classes like that:

-class Message
+class Message extends \stdClass
{

This allows using dynamic properties.

stanislav-janu avatar Jan 04 '23 09:01 stanislav-janu

@stanislav-janu Ideally, we would fix this error by not assign dynamic properties to classes in PHP.

The error I'm getting is:

PHP Deprecated:  Creation of dynamic property Google\Protobuf\Internal\MapFieldIter::$key_type is deprecated in google/protobuf/src/Google/Protobuf/Internal/MapFieldIter.php on line 63

There may be other instances of this error, however. Could you provide the stack trace for yours?

bshaffer avatar Jan 06 '23 19:01 bshaffer

PHP Deprecated: Creation of dynamic property Google\Analytics\Data\V1beta\ResponseMetaData::$_schema_restriction_response is deprecated in /var/www/gas/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:152

PHP Deprecated: Creation of dynamic property Google\Ads\GoogleAds\V11\Resources\Campaign::$_id is deprecated in /var/www/gas/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:152

stanislav-janu avatar Jan 09 '23 11:01 stanislav-janu

I see, it seems like these issues are actually in the subclasses, but the warning is thrown in the Message class, since it's the parent class.

This is a different issue than the one I fixed, so we should keep this open.

bshaffer avatar Jan 09 '23 20:01 bshaffer

@stanislav-janu I looked into this a little more, and the expected property is $schema_restriction_response, so I'm not sure why the one you have is prefixed with an underscore. Is it possible that you're using an outdated version of protobuf?

Run composer info google/protobuf, and provide to us the version you're using. Also, if you could, run php -i | grep proto and provide the results as well (to see if you're using the protobuf extension)

bshaffer avatar Jan 09 '23 22:01 bshaffer

In composer I have:

		"google/apiclient": "^2.12",
		"google/analytics-admin": "^0.6.2",
		"google/analytics-data": "^0.8.0",
		"googleads/google-ads-php": "^17",

in composer.lock I see:

            "name": "google/protobuf",
            "version": "v3.21.12",

After i tried upgrade, is it same:

		"google/apiclient": "^2.13",
		"google/analytics-admin": "^0.8",
		"google/analytics-data": "^0.9",
		"googleads/google-ads-php": "^17",

Problem maybe in repo googleapis/php-analytics-data/metadata/V1Beta/Data.php:171, there I see underscored $_schema_restriction_response.

stanislav-janu avatar Jan 10 '23 12:01 stanislav-janu

@stanislav-janu that part of the file is binary, so I'm not sure that's what is causing it. Could you provide the code you used to duplicate the issue? I tried with the following and was unsuccessful:

$r = new \Google\Analytics\Data\V1beta\ResponseMetaData();
$r->setSchemaRestrictionResponse(new \Google\Analytics\Data\V1beta\ResponseMetaData\SchemaRestrictionResponse());
echo $r->serializeToJsonString();
// {"schemaRestrictionResponse":{}}

bshaffer avatar Jan 10 '23 16:01 bshaffer

I get a lot of errors about deprecation but only for oneof or optional fields. Here is example

[2023-01-12T13:32:46.169434+01:00] deprecation.INFO: Deprecated: Creation of dynamic property DeliveryItem::$_disabled is deprecated {"exception":"[object] (ErrorException(code: 0): Deprecated: Creation of dynamic property DeliveryItem::$_total is deprecated at .../vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:152)"} []

here is the code of google/protobuf/src/Google/Protobuf/Internal/Message.php in my case the disabled is optional bool disabled and the code is generating _disbaled property

} else if ($field->getOneofIndex() !== -1) {
    $oneof = $this->desc->getOneofDecl()[$field->getOneofIndex()];
    $oneof_name = $oneof->getName();                      //<--------$oneof_name = '_disbaled`
    $this->$oneof_name = new OneofField($oneof);
} else if ($field->getLabel() === GPBLabel::OPTIONAL &&

s2x avatar Jan 12 '23 12:01 s2x

All the errors reported to me come from the same place vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php in Google\Protobuf\Internal\Message::initWithGeneratedPool at line 152 https://github.com/protocolbuffers/protobuf/blob/main/php/src/Google/Protobuf/Internal/Message.php#L152

stanislav-janu avatar Feb 01 '23 14:02 stanislav-janu

Hi. I have the same issue. I see there is a problem with release/sync script.

https://github.com/protocolbuffers/protobuf-php/commit/1fc16ac4b14107db52597c98b08a80a85a3167d5 img

There are all the fixes of PHP 8.2 deprecations in this commit (master branch)... But look at the tag name: vnull

@stanislav-janu you can try to install the package with all fixes using composer require google/protobuf:"dev-master as 3.21.12" or composer require google/protobuf:vnull

roxblnfk avatar Feb 07 '23 05:02 roxblnfk

@roxblnfk I have no issue after this upgrade. Thank you.

stanislav-janu avatar Feb 07 '23 08:02 stanislav-janu

FYI v3.22.0 was released. https://github.com/protocolbuffers/protobuf-php/releases/tag/v3.22.0

roxblnfk avatar Feb 18 '23 19:02 roxblnfk