|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-02-03 22:57 UTC] almamu at almamu dot com
[2016-02-03 23:06 UTC] requinix@php.net
-Status: Open
+Status: Suspended
[2016-02-03 23:06 UTC] requinix@php.net
[2016-02-03 23:21 UTC] almamu at almamu dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 12:00:01 2025 UTC |
Description: ------------ The return type hinting is not working as expected, in this case I want to return a "resource" (such as the ones returned by curl functions, mysql functions, etc) but PHP thinks I must return an instance of an (non-existant) "resource" class, which breaks the purpose of the return type hinting in this function, the documentation on this lacks some specific information for some php types (like mixed, object and resource), so I may be making a mistake here (and probably too much assumptions). Test script: --------------- <?php declare(strict_types=1); function prepareCURLResource(string $url) : resource { $curl = curl_init($url); curl_setopt($curl, CURLOPT_COOKIEFILE, "/tmp"); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3); return $curl; } $res = prepareCURLResource("http://localhost"); echo htmlentities(curl_exec($curl)); Expected result: ---------------- The source code of the given URL (http://localhost) in this case. Actual result: -------------- [Wed Feb 03 22:46:42 2016] [warn] [client 192.168.100.2] mod_fcgid: stderr: PHP Fatal error: Uncaught TypeError: Return value of prepareCURLResource() must be an instance of resource, resource returned in /var/www/test.php:12 [Wed Feb 03 22:46:42 2016] [warn] [client 192.168.100.2] mod_fcgid: stderr: Stack trace: [Wed Feb 03 22:46:42 2016] [warn] [client 192.168.100.2] mod_fcgid: stderr: #0 /var/www/test.php(15): prepareCURLResource('http://localhost') [Wed Feb 03 22:46:42 2016] [warn] [client 192.168.100.2] mod_fcgid: stderr: #1 {main} [Wed Feb 03 22:46:42 2016] [warn] [client 192.168.100.2] mod_fcgid: stderr: thrown in /var/www/test.php on line 12