3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function hhb_curl_init($custom_options_array = array()) { if(empty($custom_options_array)){ $custom_options_array=array(); //i feel kinda bad about this.. argv[1] of curl_init wants a string(url), or NULL //at least i want to allow NULL aswell :/ } if (!is_array($custom_options_array)) { throw new InvalidArgumentException('$custom_options_array must be an array!'); }; $options_array = array( CURLOPT_AUTOREFERER => true, CURLOPT_BINARYTRANSFER => true, CURLOPT_COOKIESESSION => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_FORBID_REUSE => false, CURLOPT_HTTPGET => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 11, //CURLOPT_REFERER=>'hanshenrik.tk', ); if (!array_key_exists(CURLOPT_COOKIEFILE, $custom_options_array)) { //do this only conditionally because tmpfile() call.. //we want PHP5.3- support -.- //for 5.4, just: $options_array[CURLOPT_COOKIEFILE]=stream_get_meta_data(tmpfile())['uri']; //static arr workaround for https://bugs.php.net/bug.php?id=66014 ... static $curl_cookiefile_filehandle_arr=array(); $curl_filehandle_arr[]=$options_array[CURLOPT_COOKIEFILE] = tmpfile(); $options_array[CURLOPT_COOKIEFILE] =stream_get_meta_data($options_array[CURLOPT_COOKIEFILE]); $options_array[CURLOPT_COOKIEFILE]=$options_array[CURLOPT_COOKIEFILE]['uri']; } //we can't use array_merge() because of how it handles integer-keys, it would/could cause corruption foreach($custom_options_array as $key => $val) { $options_array[$key] = $val; } unset($key, $val, $custom_options_array); $curl = curl_init(); curl_setopt_array($curl, $options_array); return $curl; } for($i=0;$i<9;++$i){ var_dump(hhb_curl_init()); }
Output for 7.0.0 - 7.1.0
Notice: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' in /in/YE23c on line 12 Notice: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' in /in/YE23c on line 13 Notice: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' in /in/YE23c on line 14 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' in /in/YE23c on line 15 Notice: Use of undefined constant CURLOPT_FORBID_REUSE - assumed 'CURLOPT_FORBID_REUSE' in /in/YE23c on line 16 Notice: Use of undefined constant CURLOPT_HTTPGET - assumed 'CURLOPT_HTTPGET' in /in/YE23c on line 17 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/YE23c on line 18 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/YE23c on line 19 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in /in/YE23c on line 20 Notice: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /in/YE23c on line 21 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 24 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 30 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/YE23c:40 Stack trace: #0 /in/YE23c(45): hhb_curl_init() #1 {main} thrown in /in/YE23c on line 40
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
resource(5) of type (curl) resource(6) of type (curl) resource(7) of type (curl) resource(8) of type (curl) resource(9) of type (curl) resource(10) of type (curl) resource(11) of type (curl) resource(12) of type (curl) resource(13) of type (curl)
Output for 5.1.0 - 5.6.28
Notice: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' in /in/YE23c on line 12 Notice: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' in /in/YE23c on line 13 Notice: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' in /in/YE23c on line 14 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' in /in/YE23c on line 15 Notice: Use of undefined constant CURLOPT_FORBID_REUSE - assumed 'CURLOPT_FORBID_REUSE' in /in/YE23c on line 16 Notice: Use of undefined constant CURLOPT_HTTPGET - assumed 'CURLOPT_HTTPGET' in /in/YE23c on line 17 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/YE23c on line 18 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/YE23c on line 19 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in /in/YE23c on line 20 Notice: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /in/YE23c on line 21 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 24 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 30 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Fatal error: Call to undefined function curl_init() in /in/YE23c on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Notice: Use of undefined constant CURLOPT_AUTOREFERER - assumed 'CURLOPT_AUTOREFERER' in /in/YE23c on line 12 Notice: Use of undefined constant CURLOPT_BINARYTRANSFER - assumed 'CURLOPT_BINARYTRANSFER' in /in/YE23c on line 13 Notice: Use of undefined constant CURLOPT_COOKIESESSION - assumed 'CURLOPT_COOKIESESSION' in /in/YE23c on line 14 Notice: Use of undefined constant CURLOPT_FOLLOWLOCATION - assumed 'CURLOPT_FOLLOWLOCATION' in /in/YE23c on line 15 Notice: Use of undefined constant CURLOPT_FORBID_REUSE - assumed 'CURLOPT_FORBID_REUSE' in /in/YE23c on line 16 Notice: Use of undefined constant CURLOPT_HTTPGET - assumed 'CURLOPT_HTTPGET' in /in/YE23c on line 17 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/YE23c on line 18 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/YE23c on line 19 Notice: Use of undefined constant CURLOPT_CONNECTTIMEOUT - assumed 'CURLOPT_CONNECTTIMEOUT' in /in/YE23c on line 20 Notice: Use of undefined constant CURLOPT_TIMEOUT - assumed 'CURLOPT_TIMEOUT' in /in/YE23c on line 21 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 24 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 30 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 31 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Notice: Use of undefined constant CURLOPT_COOKIEFILE - assumed 'CURLOPT_COOKIEFILE' in /in/YE23c on line 32 Notice: Undefined index: uri in /in/YE23c on line 32 Fatal error: Call to undefined function curl_init() in /in/YE23c on line 40
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/YE23c on line 9
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/YE23c on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/YE23c on line 9
Process exited with code 255.