Bug->Req #81450 [Nab]: object type hint does not accept resource
| From: | danack@php.net | Date: | Thu, 16 Sep 2021 23:13:43 +0000 |
| Subject: | Bug->Req #81450 [Nab]: object type hint does not accept resource | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236657@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81450&edit=1
ID: 81450
Updated by: danack@php.net
Reported by: gib-o-master at mail dot ru
Summary: object type hint does not accept resource
Status: Not a bug
-Type: Bug
+Type: Feature/Change Request
Package: *General Issues
PHP Version: 8.0.10
Block user comment: N
Private report: N
New Comment:
> why object hint does not accept resource?
Because resources are not objects. Resources are their own type and so don't pass the object
type check.
> will it be fixed in future versions of php?
Yes, but not by making resource pass the object type check.
There is an on-going effort to replace all resource types with opaque objects. There is a list of
the progress here: https://github.com/php/php-tasks/issues/6
So at some point proc_open(..) will be changed from returning a resource, to returning a
'Proc' or 'Process' object.
Previous Comments:
------------------------------------------------------------------------
[2021-09-16 23:11:13] requinix@php.net
Resources are not objects.
https://www.php.net/manual/en/language.types.declarations.php
------------------------------------------------------------------------
[2021-09-16 22:58:47] gib-o-master at mail dot ru
Description:
------------
i do proc_open() which returns resource https://www.php.net/manual/en/function.proc-open
$proc = proc_open(..);
$hand = new ProcessController($proc);
i pass it to the constructor function which has object type hint
function __construct(public object $proc)
{..}
the result is "($proc) must be of type object, resource given"
why object hint does not accept resource? will it be fixed in future versions of php?
Expected result:
----------------
resource is accepted
Actual result:
--------------
TypeError exception
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81450&edit=1