restore php-5.3 compatibility
authorMichael Wallner <mike@php.net>
Thu, 19 Feb 2015 07:40:49 +0000 (08:40 +0100)
committerMichael Wallner <mike@php.net>
Thu, 19 Feb 2015 07:40:49 +0000 (08:40 +0100)
22 files changed:
php_http_client_curl.c
php_http_object.c
tests/bug66891.phpt
tests/client008.phpt
tests/client015.phpt
tests/client016.phpt
tests/client017.phpt
tests/client018.phpt
tests/client021.phpt
tests/client023.phpt
tests/client025.phpt
tests/client026.phpt
tests/envresponse004.phpt
tests/envresponse017.phpt
tests/headerparser001.phpt
tests/headerparser002.phpt
tests/headerparser003.phpt
tests/helper/pipeline.inc
tests/helper/server.inc
tests/info002.phpt
tests/messageparser001.phpt
tests/skipif.inc

index 97408bddb469deb3901bd8ddd561880c0fd8e5dc..44b2c21a9cc819a842e50cabcc23d6dbbb13c558 100644 (file)
@@ -2344,7 +2344,8 @@ static int apply_available_options(void *pDest TSRMLS_DC, int num_args, va_list
                if (Z_TYPE(opt->defval) == IS_STRING && !Z_STRVAL(opt->defval)) {
                        ZVAL_NULL(entry);
                } else {
-                       ZVAL_ZVAL(entry, &opt->defval, 1, 0);
+                       ZVAL_COPY_VALUE(entry, &opt->defval);
+                       zval_copy_ctor(entry);
                }
        }
 
index 7d902eaa3c84f66b19bc169c18ac987366d8017c..ba6d28c82b8b7fed832cc9327d73bca8782a3d6d 100644 (file)
@@ -53,6 +53,15 @@ STATUS php_http_new(zend_object_value *ovp, zend_class_entry *ce, php_http_new_t
        return SUCCESS;
 }
 
+static inline zend_function *get_object_method(zval *zobject, zval *zmeth TSRMLS_DC)
+{
+#if PHP_VERSION_ID >= 50400
+       return Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(zmeth), Z_STRLEN_P(zmeth), NULL TSRMLS_CC);
+#else
+       return Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(zmeth), Z_STRLEN_P(zmeth) TSRMLS_CC);
+#endif
+}
+
 php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *cb, zval *zobject, const char *method_str, size_t method_len TSRMLS_DC)
 {
        zval *zfn;
@@ -70,7 +79,7 @@ php_http_object_method_t *php_http_object_method_init(php_http_object_method_t *
        cb->fci.function_name = zfn;
        cb->fcc.initialized = 1;
        cb->fcc.calling_scope = cb->fcc.called_scope = Z_OBJCE_P(zobject);
-       cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(cb->fci.function_name), Z_STRLEN_P(cb->fci.function_name), NULL TSRMLS_CC);
+       cb->fcc.function_handler = get_object_method(zobject, cb->fci.function_name TSRMLS_CC);
 
        return cb;
 }
@@ -108,7 +117,7 @@ STATUS php_http_object_method_call(php_http_object_method_t *cb, zval *zobject,
 
        if (cb->fcc.called_scope != Z_OBJCE_P(zobject)) {
                cb->fcc.called_scope = Z_OBJCE_P(zobject);
-               cb->fcc.function_handler = Z_OBJ_HT_P(zobject)->get_method(&zobject, Z_STRVAL_P(cb->fci.function_name), Z_STRLEN_P(cb->fci.function_name), NULL TSRMLS_CC);
+               cb->fcc.function_handler = get_object_method(zobject, cb->fci.function_name TSRMLS_CC);
        }
 
        rv = zend_call_function(&cb->fci, &cb->fcc TSRMLS_CC);
index 0fd84f882b4f03a0c026452d18d056e475490bfa..30f9d7e9b16aaf8373fb375ba6426ef06368d46f 100644 (file)
@@ -12,7 +12,7 @@ header("WWW-Authenticate: none");
 $r = new http\Env\Response;
 $r->setResponseCode(200);
 $r->send();
-var_dump(http_response_code());
+var_dump(http\Env::getResponseCode());
 ?>
 --EXPECT--
 int(200)
\ No newline at end of file
index f8b8774eb8edc1c7511b8c7961438470fd9d5a88..98fc8f8aebc34d9da458bbf1a252a10f208b8e83 100644 (file)
@@ -18,7 +18,7 @@ server("pipeline.inc", function($port, $stdin) {
        $request = new http\Client\Request("GET", "http://localhost:$port");
        
        $client = new http\Client();
-       $client->configure(["pipelining" => true, "use_eventloop" => true]);
+       $client->configure(array("pipelining" => true, "use_eventloop" => true));
 
        $client->enqueue($request);
        $client->send();
index 70b5f43bc603c8a417bc08eeeac0d5c5787ba674..f378653808824a2eb873857fe5242d8267fb86bc 100644 (file)
@@ -16,8 +16,8 @@ server("proxy.inc", function($port) {
        $client1 = new http\Client;
        $client2 = new http\Client;
        
-       $client1->configure(["use_eventloop" => true]);
-       $client2->configure(["use_eventloop" => true]);
+       $client1->configure(array("use_eventloop" => true));
+       $client2->configure(array("use_eventloop" => true));
        
        $client1->enqueue(new http\Client\Request("GET", "http://localhost:$port/"));
        $client2->enqueue(new http\Client\Request("GET", "http://localhost:$port/"));
index 58f97c1ff0332cf8a1e7cace580e33499063e5df..d2aef073d08d986cec6cdc839a315aafe17224bf 100644 (file)
@@ -17,7 +17,7 @@ server("proxy.inc", function($port) {
        
        foreach (http\Client::getAvailableDrivers() as $driver) {
                $client = new http\Client($driver);
-               $client->configure(["use_eventloop" => true]);
+               $client->configure(array("use_eventloop" => true));
                $client->enqueue($request);
        
                while ($client->once()) {
index ea54146dcbe8bed7c1b82bc633d8dd1cd005c946..a50502803590a0e93c366f51569127b3503ea391 100644 (file)
@@ -12,7 +12,7 @@ skip_client_test();
 echo "Test\n";
 
 $client = new http\Client;
-$client->setOptions(["compress" => true]);
+$client->setOptions(array("compress" => true));
 
 $client->enqueue(new http\Client\Request("GET", "http://dev.iworks.at/ext-http/.print_request.php"));
 $client->send();
index 7acb911ad6c94a92ea51dd5a203be964200cceaa..c3ca9f96f3f655b9dff2f602187ed8f32b704955 100644 (file)
@@ -17,7 +17,7 @@ server("pipeline.inc", function($port, $stdin, $stdout, $stderr) {
        fputs($stdin, "3\n");
        
        $client = new http\Client(null);
-       $client->configure(["pipelining" => true, "max_host_connections" => 0]);
+       $client->configure(array("pipelining" => true, "max_host_connections" => 0));
        
        /* this is just to let curl know the server may be capable of pipelining */
        $client->enqueue(new http\Client\Request("GET", "http://localhost:$port"));
index 41a220a6d48e7925924761c966461790db6b05ab..1335aaa8ebe80bd9f0c068ea4e3921a1d54b229a 100644 (file)
@@ -14,10 +14,10 @@ echo "Test\n";
 
 $tmpfile = tempnam(sys_get_temp_dir(), "cookie.");
 $request = new http\Client\Request("GET", "http://localhost");
-$request->setOptions(["cookiestore" => $tmpfile]);
+$request->setOptions(array("cookiestore" => $tmpfile));
 
 server("cookie.inc", function($port) use($request) {
-       $request->setOptions(["port" => $port]);
+       $request->setOptions(array("port" => $port));
        $client = new http\Client;
        echo $client->requeue($request)->send()->getResponse();
        echo $client->requeue($request)->send()->getResponse();
@@ -25,7 +25,7 @@ server("cookie.inc", function($port) use($request) {
 });
 
 server("cookie.inc", function($port) use($request) {
-       $request->setOptions(["port" => $port]);
+       $request->setOptions(array("port" => $port));
        $client = new http\Client;
        echo $client->requeue($request)->send()->getResponse();
        echo $client->requeue($request)->send()->getResponse();
@@ -33,7 +33,7 @@ server("cookie.inc", function($port) use($request) {
 });
 
 server("cookie.inc", function($port) use($request) {
-       $request->setOptions(["port" => $port, "cookiesession" => true]);
+       $request->setOptions(array("port" => $port, "cookiesession" => true));
        $client = new http\Client;
        echo $client->requeue($request)->send()->getResponse();
        echo $client->requeue($request)->send()->getResponse();
@@ -41,7 +41,7 @@ server("cookie.inc", function($port) use($request) {
 });
 
 server("cookie.inc", function($port) use($request) {
-       $request->setOptions(["port" => $port, "cookiesession" => false]);
+       $request->setOptions(array("port" => $port, "cookiesession" => false));
        $client = new http\Client;
        echo $client->requeue($request)->send()->getResponse();
        echo $client->requeue($request)->send()->getResponse();
index b09c2e2b655337618bc7b50c48465ec8c0009f66..77ea7cee6f81deb3a3eb25e56057e6243a56d6dd 100644 (file)
@@ -22,11 +22,11 @@ foreach ($avail as $k => $v) {
                $oo = $opt[$k];
                foreach ($v as $kk => $vv) {
                        if (isset($vv) && $oo[$kk] !== $vv) {
-                               var_dump([$kk => [$vv, $oo[$kk]]]);
+                               var_dump(array($kk => array($vv, $oo[$kk])));
                        }
                }
        } else if (isset($v) && $opt[$k] !== $v) {
-               var_dump([$k => [$v, $opt[$k]]]);
+               var_dump(array($k => array($v, $opt[$k])));
        }
 }
 var_dump($client === $client->configure($client->getAvailableConfiguration()));
index 18c5095cdf01d8289f4b61991aea2d3805db903c..866cd2e1502f8e0fa629dac64f40b17ed693c0f5 100644 (file)
@@ -14,7 +14,7 @@ echo "Test\n";
 server("proxy.inc", function($port) {
        $client = new http\Client;
        $request = new http\Client\Request("PUT", "http://localhost:$port");
-       $request->setOptions(["resume" => 1, "expect_100_timeout" => 0]);
+       $request->setOptions(array("resume" => 1, "expect_100_timeout" => 0));
        $request->getBody()->append("123");
        echo $client->enqueue($request)->send()->getResponse();
 });
index d89e98ef592f7dbf5bed6a9a75cbb36b2bb64f3b..1bafdc1b154d1d08a663e1856135b2e83e2f78ae 100644 (file)
@@ -19,7 +19,7 @@ server("proxy.inc", function($port) {
        for ($i = 0, $data = str_repeat("a",1024); $i < 128*1024; ++$i) {
                $request->getBody()->append($data);
        }
-       $request->setOptions(["timeout" => 10, "expect_100_timeout" => 0]);
+       $request->setOptions(array("timeout" => 10, "expect_100_timeout" => 0));
        $client->enqueue($request);
        $client->send();
        var_dump($client->getResponse()->getHeaders());
index deee3f2081b8d397fafb4a6a77259d46fb276862..da5801d06ac3f8bcfea5674cea1fe9f6ab4ca73d 100644 (file)
@@ -20,6 +20,7 @@ echo "bar";
 
 ob_end_flush();
 $r->send();
+?>
 --EXPECTHEADERS--
 Accept-Ranges: bytes
 Cache-Control: public,must-revalidate,max-age=0
index ffa40cbb6f13fcd444c18ace971671e9b77d4393..4c832f25536f4fb652ea4fc9bbaf22b6ff7902fc 100644 (file)
@@ -10,7 +10,7 @@ echo "Test\n";
 
 $req = new http\Env\Request;
 $req->setRequestMethod("CONNECT");
-$req->setRequestUrl(["host"=>"www.example.com", "port"=>80]);
+$req->setRequestUrl(array("host"=>"www.example.com", "port"=>80));
 
 echo $req;
 
index 0a1eb37ad676a5c31db57d9b5ed7729e3ad6db82..cdd55e4fefd9480992d934ffe7f3a13bff02e14f 100644 (file)
@@ -8,16 +8,16 @@ include "skipif.inc";
 <?php
 echo "Test\n";
 
-$headers = [
+$headers = array(
        "One: ","header\n",
        "Two: header\n\tlines\n",
        "Three",": header\n lines\n here\n",
        "More: than one header\n",
        "More: ", "than: ", "you: ", "expect\n",
        "\n",
-];
+);
 
-$states = [-1=>"FAILURE",0=>"START","KEY","VALUE","VALUE_EX","HEADER_DONE","DONE"];
+$states = array(-1=>"FAILURE",0=>"START","KEY","VALUE","VALUE_EX","HEADER_DONE","DONE");
 $parser = new http\Header\Parser;
 do {
        $state = $parser->parse($part = array_shift($headers), 
index c5a02f19778c4e0f705971b10e7e17175204ae55..67e6681f25e391644593ad57d8eae7dfe2f7b123 100644 (file)
@@ -8,14 +8,14 @@ include "skipif.inc";
 <?php 
 echo "Test\n";
 
-$headers = [
+$headers = array(
        "Na\0me: value",
        "Na\nme: value",
        "Name:\0value",
        "Name:\nvalue",
        "Name: val\0ue",
        "Name: value\0",
-];
+);
 
 foreach ($headers as $header) {
        $parsed = null;
index e1954e7a0a02011fc665cccea721a4c4e3a660ea..1216fac16797196b093ad8f235979cd8a8a7ba07 100644 (file)
@@ -12,12 +12,12 @@ $parser = new http\Header\Parser;
 $socket = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP);
 stream_set_blocking($socket[0], 0);
 
-$headers = [
+$headers = array(
 "GET / HTTP/1.1\n",
 "Host: localhost","\n",
 "Content","-length: 3\n",
 "\n",
-];
+);
 
 while ($headers) {
        $line = array_shift($headers);
index 815b46339b672574284138ec976cf8da0b472827..b7175c109fac1b24d4f4a31e000e08cda288ae4d 100644 (file)
@@ -3,7 +3,8 @@
 include "server.inc";
 
 function respond($client, $msg) {
-       (new http\Env\Response)->setEnvRequest($msg)
+       $r = new http\Env\Response;
+       $r->setEnvRequest($msg)
                ->setHeader("X-Req", $msg->getRequestUrl())
                ->send($client);
 }
index 0605adc145a9871f0051ea6d4d926b5886e32fa7..aa8559f8c41fbb3480f1e6dbcf6a02de0a3659b6 100644 (file)
@@ -1,11 +1,16 @@
 <?php 
 
-function serve(callable $cb) {
+// PHP-5.3
+if (!defined("PHP_BINARY")) {
+       define("PHP_BINARY", PHP_BINDIR.DIRECTORY_SEPARATOR."php");
+}
+
+function serve($cb) {
        foreach (range(8000, 9000) as $port) {
                if (($server = @stream_socket_server("tcp://localhost:$port"))) {
                        fprintf(STDERR, "%s\n", $port);
                        do {
-                               $R = [$server]; $W = []; $E = [];
+                               $R = array($server); $W = array(); $E = array();
                                $select = stream_select($R, $E, $E, 0, 10000);
                                if ($select && ($client = stream_socket_accept($server, 1))) {
                                        if (getenv("PHP_HTTP_TEST_SSL")) {
@@ -29,12 +34,12 @@ function serve(callable $cb) {
        }
 }
 
-function server($handler, callable $cb) {
-       proc(PHP_BINARY, [__DIR__."/$handler"], $cb);
+function server($handler, $cb) {
+       proc(PHP_BINARY, array(__DIR__."/$handler"), $cb);
 }
 
-function nghttpd(callable $cb) {
-       $spec = [["pipe","r"], ["pipe","w"], ["pipe","w"]];
+function nghttpd($cb) {
+       $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
        foreach (range(8000, 9000) as $port) {
                $comm = "exec nghttpd -d html $port http2.key http2.crt";
                if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
@@ -65,8 +70,8 @@ function nghttpd(callable $cb) {
                        
 }
 
-function proc($bin, $args, callable $cb) {
-       $spec = [["pipe","r"], ["pipe","w"], ["pipe","w"]];
+function proc($bin, $args, $cb) {
+       $spec = array(array("pipe","r"), array("pipe","w"), array("pipe","w"));
        $comm = escapeshellcmd($bin) . " ". implode(" ", array_map("escapeshellarg", $args));
        if (($proc = proc_open($comm, $spec, $pipes, __DIR__))) {
                $stdin = $pipes[0];
@@ -75,7 +80,7 @@ function proc($bin, $args, callable $cb) {
                
                do {
                        $port = trim(fgets($stderr));
-                       $R = [$stderr]; $W = []; $E = [];
+                       $R = array($stderr); $W = array(); $E = array();
                } while (is_numeric($port) && stream_select($R, $W, $E, 0, 10000));
        
                if (is_numeric($port)) {
index 72690e472ba290db865fa54e4e8cb5cdc995daa7..093dcd169c63e3334271666cb390efa4693f4cba 100644 (file)
@@ -9,7 +9,7 @@ include "skipif.inc";
 
 echo "Test\n";
 
-function trap(callable $cb) {
+function trap($cb) {
        try {
                $cb();
        } catch (Exception $e) { 
index d2d22a50aafe2c2d1eaa857f8eb59878c7bb3d93..1167c64115b2d85d8ef07958dad756f36f77e017 100644 (file)
@@ -26,7 +26,7 @@ foreach (glob(__DIR__."/data/message_*.txt") as $file) {
        }
        
        if (!$string) {
-               $s = ["START", "HEADER", "HEADER_DONE", "BODY", "BODY_DUMB", "BODY_LENGTH", "BODY_CHUNK", "BODY_DONE", "UPDATE_CL", "DONE"];
+               $s = array("START", "HEADER", "HEADER_DONE", "BODY", "BODY_DUMB", "BODY_LENGTH", "BODY_CHUNK", "BODY_DONE", "UPDATE_CL", "DONE");
                printf("Unexpected state: %s (%s)\n", $s[$parser->getState()], $file);
        }
 
index cceeaf077e82820daeea9e84423986ac1524177a..4ab631e63d5b9b00b2e1be2c3efe174bfc3791bb 100644 (file)
@@ -21,9 +21,11 @@ function skip_client_test($message = "skip need a client driver\n") {
 }
 
 function skip_http2_test($message = "skip need http2 support (nghttpd in PATH)\n") {
-       foreach (explode(":", $_ENV["PATH"]) as $path) {
-               if (is_executable($path . "/nghttpd")) {
-                       return;
+       if (defined("http\\Client\\Curl\\HTTP_VERSION_2_0")) {
+               foreach (explode(":", $_ENV["PATH"]) as $path) {
+                       if (is_executable($path . "/nghttpd")) {
+                               return;
+                       }
                }
        }
        die($message);