Bug #71518 [NEW]: Return type hinting for resources

From: Date: Wed, 03 Feb 2016 22:55:42 +0000
Subject: Bug #71518 [NEW]: Return type hinting for resources
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-199036@lists.php.net to get a copy of this message
From: almamu at almamu dot com Operating system: Ubuntu 12.04 PHP version: 7.0.2 Package: Variables related Bug Type: Bug Bug description:Return type hinting for resources 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 -- Edit bug report at https://bugs.php.net/bug.php?id=71518&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71518&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71518&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71518&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=71518&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=71518&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=71518&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=71518&r=needscript Try newer version: https://bugs.php.net/fix.php?id=71518&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=71518&r=support Expected behavior: https://bugs.php.net/fix.php?id=71518&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=71518&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=71518&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=71518&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71518&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=71518&r=dst IIS Stability: https://bugs.php.net/fix.php?id=71518&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=71518&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=71518&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=71518&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=71518&r=mysqlcfg

« previous php.bugs (#199036) next »