Bug #78481 [Opn->Nab]: Can't use resource as typed param
| From: | requinix@php.net | Date: | Sat, 31 Aug 2019 08:46:08 +0000 |
| Subject: | Bug #78481 [Opn->Nab]: Can't use resource as typed param | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222503@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78481&edit=1
ID: 78481
Updated by: requinix@php.net
Reported by: momchil at bojinov dot info
Summary: Can't use resource as typed param
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows 10
PHP Version: 7.4.0beta4
Block user comment: N
Private report: N
New Comment:
resource is not available as for type declarations because it says nothing about what type of
resource it is. Your function would allow GD resources, but also file streams and cURL handles and
other things you don't want. The type would be a false sense of security and so is not
supported.
Previous Comments:
------------------------------------------------------------------------
[2019-08-31 08:26:13] momchil at bojinov dot info
Description:
------------
I am trying to use resource for parameter type but I get TypeError
Test script:
---------------
$Picture = imagecreatetruecolor(100, 100);
class bla
{
public function forPChart(resource $picture, $X, $Y)
{
$this->createImage($picture);
}
}
(new bla())->forPChart($Picture, 0 ,0);
Expected result:
----------------
Actual result:
--------------
Fatal error: Uncaught TypeError: Argument 1 passed to bla::forPChart() must be an instance of
resource, resource given, called in E:\xxx\test.php on line 13 and defined in E:\xxx\test.php:7
Stack trace:
#0 E:\xxx\test.php(13): bla->forPChart(Resource id #4, 0, 0)
#1 {main}
thrown in E:\xxx\test.php on line 7
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78481&edit=1