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 97408bd..44b2c21 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 7d902ea..ba6d28c 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 0fd84f8..30f9d7e 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 f8b8774..98fc8f8 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 70b5f43..f378653 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 58f97c1..d2aef07 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 ea54146..a505028 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 7acb911..c3ca9f9 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 41a220a..1335aaa 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 b09c2e2..77ea7ce 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 18c5095..866cd2e 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 d89e98e..1bafdc1 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 deee3f2..da5801d 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 ffa40cb..4c832f2 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 0a1eb37..cdd55e4 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 c5a02f1..67e6681 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 e1954e7..1216fac 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 815b463..b7175c1 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 0605adc..aa8559f 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 72690e4..093dcd1 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 d2d22a5..1167c64 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 cceeaf0..4ab631e 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);