Bug #78480 [NEW]: The typed properties miss an important "function"

From: Date: Fri, 30 Aug 2019 21:27:50 +0000
Subject: Bug #78480 [NEW]: The typed properties miss an important "function"
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222499@lists.php.net to get a copy of this message
From:             manchokapitancho at gmail dot com
Operating system: 
PHP version:      7.4.0beta4
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:The typed properties miss an important "function"

Description:
------------
The new PHP 7.4 feature - typed properties is a great addition to the
language.
As a side effect it adds a brand new state of the class/object
properties - initialized=yes/no.
If one tries to access an uninitialized property, a TypeError is being
thrown.
isset($object->prop) does not trigger TypeError but it returns false if
$object->prop is NULL.
The suggested check is only indirectly possible via the long construct
(new ReflectionProperty(<name>::class, '<prop>'))->isInitialized($obj)

On the other side, unset works perfectly well and returns a property
back into the uninitialized state.

This write-only asymmetry is not consistent and I would expect a
language construct similar to isset [e.g. is_initialized($obj->prop)]
that handles this case.

Test script:
---------------
class test {
	public ?int $prop;
}
$obj = new test;

var_dump(isset($obj->prop));
var_dump(is_initialized($obj->prop));

$obj->prop = null;

var_dump(isset($obj->prop));
var_dump(is_initialized($obj->prop));



Expected result:
----------------
false
false
false
true

Actual result:
--------------
false
<missing>
false
<missing>

-- 
Edit bug report at https://bugs.php.net/bug.php?id=78480&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=78480&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=78480&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=78480&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=78480&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=78480&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=78480&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=78480&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=78480&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=78480&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=78480&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78480&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=78480&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=78480&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=78480&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=78480&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=78480&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=78480&r=mysqlcfg



Thread (10 messages)

« previous php.bugs (#222499) next »