|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-08-31 08:26 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 01:00:02 2025 UTC |
The "must be an instance of resource, resource given" confusion sounds familiar but I can't find an existing bug for it. I'm not sure it's easily fixable anyways as what's happening is that PHP is trying to get a variable that's an instance of a class ("resource") and it found a non-object variable type (a resource) instead - the error message just fills in a "must be an instance of $expected, $actual given" template. Anyway, I did find bug #71518 from 2016 where I gave a more helpful answer.