Req #80720 [NEW]: Class, Interface and Trait pseudo-types

From: Date: Sun, 07 Feb 2021 08:07:59 +0000
Subject: Req #80720 [NEW]: Class, Interface and Trait pseudo-types
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231974@lists.php.net to get a copy of this message
From:             klaussantana at gmail dot com
Operating system: Any
PHP version:      8.0.2
Package:          Unknown/Other Function
Bug Type:         Feature/Change Request
Bug description:Class, Interface and Trait pseudo-types

Description:
------------
---
From manual page: https://php.net/language.types.declarations
---

If you use those pseudo-types to define a parameter|variable|UnionType,
it'll assume a String value containing a valid Class|Interface|Trait
full qualified name only if it passes through their respective *_exists
functions. It can also assume an object as value.

Otherwise a runtime exception must be thrown because that no class,
interface or trait were defined with the String value as name, even
after autoload performance.

This feature can be further discussed.

Test script:
---------------
<?PHP

fn ( Class|Interface|Trait|Object $Subject )
{
   if ( is_string($Subject) )
      echo 'The parameter $Subject is a valid Class|Interface|Trait
name.';
   elseif ( is_object($Subject) ) 
      echo 'The parameter $Subject is an object of any class.';
   elseif ( $Subject === null )
      echo 'The parameter $Subject is empty.';
   else
      echo 'This code line will never run.';
   echo PHP_EOL;
}

fn ( new StdClass ); // Works.
fn ( function () {} ); // Works.
fn ( 'Defined' ); // Works.
fn ( 'Undefined' ); // Throws some runtime exception because there's no
class, interface or trait defined with that name.

Expected result:
----------------
The parameter $Subject is an object of any class.
The parameter $Subject is an object of any class.
The parameter $Subject is a valid Class|Interface|Trait name.
RuntimeException: Invalid parameters content.


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


Thread (2 messages)

« previous php.bugs (#231974) next »