Creation of dynamic property is deprecated in PHP 8.2
Please change classes like that:
-class Message
+class Message extends \stdClass
{
This allows using dynamic properties.
@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?
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
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.
@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)
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 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":{}}
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 &&
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
Hi. I have the same issue. I see there is a problem with release/sync script.
https://github.com/protocolbuffers/protobuf-php/commit/1fc16ac4b14107db52597c98b08a80a85a3167d5

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 I have no issue after this upgrade. Thank you.
FYI v3.22.0 was released.
https://github.com/protocolbuffers/protobuf-php/releases/tag/v3.22.0