[php-src] Issue #7738: object property "date" give Warnings and returns NULL

From: Date: Wed, 08 Dec 2021 13:33:26 +0000
Subject: [php-src] Issue #7738: object property "date" give Warnings and returns NULL
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238279@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7738
Author: udoattilafischer

### Description

I getting from a function following object back (sensitive information is replaced with
"xdeletedx") :

object(OpenStack\Images\v2\Models\Image)#223 (22) {
  ["status"]=>
  string(11) "deactivated"
  ["name"]=>
  string(28) "Windows 2019 Server Standard"
  ["tags"]=>
  array(7) {
    [0]=>
    string(8) "internal"
    [1]=>
    string(3) "sit"
    [2]=>
    string(5) "noSSH"
    [3]=>
    string(10) "noUserCred"
    [4]=>
    string(7) "managed"
    [5]=>
    string(7) "xdeletedx"
    [6]=>
    string(7) "windows"
  }
  ["containerFormat"]=>
  string(4) "bare"
  ["x1"]=>
  object(DateTimeImmutable)#224 (3) {
    ["date"]=>
    string(26) "2021-10-15 09:13:15.000000"
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(1) "Z"
  }
  ["diskFormat"]=>
  string(3) "raw"
  ["updatedAt"]=>
  **object(DateTimeImmutable)#225 (3) {
    ["date"]=>
    string(26) "2021-10-26 06:53:25.000000"**
    ["timezone_type"]=>
    int(2)
    ["timezone"]=>
    string(1) "Z"
  }
  ["visibility"]=>
  string(6) "public"
  ["minDisk"]=>
  int(0)
  ["protected"]=>
  bool(false)
  ["id"]=>
  string(36) "xdeletedx"
  ["fileUri"]=>
  object(GuzzleHttp\Psr7\Uri)#222 (8) {
    ["scheme":"GuzzleHttp\Psr7\Uri":private]=>
    string(5) "https"
    ["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["host":"GuzzleHttp\Psr7\Uri":private]=>
    string(34) "xdeletedy"
    ["port":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
    ["path":"GuzzleHttp\Psr7\Uri":private]=>
    string(53) "//v2/images/xdeletedx/file"
    ["query":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["fragment":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["composedComponents":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
  }
  ["checksum"]=>
  string(32) "xdeletedx"
  ["ownerId"]=>
  string(32) "xdeletedx"
  ["size"]=>
  int(25165824000)
  ["minRam"]=>
  int(0)
  ["schemaUri"]=>
  object(GuzzleHttp\Psr7\Uri)#220 (8) {
    ["scheme":"GuzzleHttp\Psr7\Uri":private]=>
    string(5) "https"
    ["userInfo":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["host":"GuzzleHttp\Psr7\Uri":private]=>
    string(34) "xdeletedx"
    ["port":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
    ["path":"GuzzleHttp\Psr7\Uri":private]=>
    string(18) "//v2/schemas/image"
    ["query":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["fragment":"GuzzleHttp\Psr7\Uri":private]=>
    string(0) ""
    ["composedComponents":"GuzzleHttp\Psr7\Uri":private]=>
    NULL
  }
  ["virtualSize"]=>
  NULL
  ["aliases"]=>
  array(6) {
    ["container_format"]=>
    string(15) "containerFormat"
    ["disk_format"]=>
    string(10) "diskFormat"
    ["min_disk"]=>
    string(7) "minDisk"
    ["owner"]=>
    string(7) "ownerId"
    ["min_ram"]=>
    string(6) "minRam"
    ["virtual_size"]=>
    string(11) "virtualSize"
  }
  ["resourcesKey"]=>
  NULL
  ["markerKey"]=>
  NULL
  ["resourceKey"]=>
  NULL
}

------------------------------------------------------------------------------

If following code is executed after getting this object back
`<?php
$imageupdate = $image->updatedAt->date;
var_dump($imageupdate);
?>`

or 

`<?php
$imageupdate1 = $image->updatedAt;
//var_dump($imageupdate1);
$imageupdate = $imageupdate1->date;
var_dump($imageupdate);
echo "Update:$imageupdate";
?>`

or 

`<?php
$imageupdate1 = $image->updatedAt;
$imageupdate = $imageupdate1->{'date'};
var_dump($imageupdate);
echo "Update:$imageupdate";
?>`

or 

`<?php
$imageupdate1 = $image->updatedAt;
$date1='date';
$imageupdate = $imageupdate1->$date1;
var_dump($imageupdate);
echo "Update:$imageupdate";
?>`


Result is (not as expected):
PHP Warning:  Undefined variable $date in xdeletedx
Warning: Undefined property: DateTimeImmutable::$date in xdeletedx

NULL
Update:

--------------------------------------------

if I use (as workaround)
`<?php
$imageupdate1 = $image->updatedAt;
$imageupdate = (array)$imageupdate1->date; 
var_dump($imageupdate);
echo "Update:$imageupdate";
?>`

Result is (as expected): 
string(26) "2021-10-19 13:32:19.000000"
Update:2021-10-19 13:32:19.000000


The date is not in the reserved words list. It is a common used property. It should be accessible
without tricks.
Expected Result:
string(26) "2021-10-19 13:32:19.000000"


### PHP Version

PHP 8.1.0 (cli) (built: Nov 23 2021 18:56:11)

### Operating System

CentOS Linux release 8.5.2111


Thread (1 message)

  • noreply@php.net
« previous php.bugs (#238279) next »