php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67514 Error load Net_Url
Submitted: 2014-06-25 16:09 UTC Modified: 2014-06-25 17:11 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: r dot mbiama at angosso dot net Assigned:
Status: Not a bug Package: Dynamic loading
PHP Version: 5.6.0RC1 OS: Linux, Php Sever
Private report: No CVE-ID: None
 [2014-06-25 16:09 UTC] r dot mbiama at angosso dot net
Description:
------------
Development net_url release the immediate availability of the first release candidate of PHP 5.6
 bugfix-Net_url release
Cpanel binaries

Test script:
---------------
<?xml version="1.0" encoding="UTF-8" ?>
<net_php>
  <parser>
    <target>data/output</target>
  </parser>
  <transformer>
    <target>data/output</target>
  </transformer>
  <files>
    <directory>.</directory>
  </files>
</net_php>
PEAR related : Bug #24998: HTTP_Request dependency of Net_URL not "working"

Expected result:
----------------
<?php
[PHP FOLDER]/data/php.tpl.xml
// $Id: URL.php,'http://www.exemple.net:2082/cpsess2421114227/frontend/x3/module_installers/live_update.html?lang=php-pear&mod=Net_URL' 2014/06/25 17:57:39 mbiama Exp $

//

// Net_URL Class

 

 <transformer>
    <target>output</target>
    <external-class-documentation>
        <prefix>HTML_QuickForm2</prefix>
        <uri>http://pear.php.net/package/HTML_QuickForm2/home/angosson/latest/HTML_QuickForm2/{CLASS}.html</uri>
    </external-class-documentation>
</transformer>

class Net_URL

{

    var $options = array('encode_query_keys' => false);

    /**

    * Full url

    * @var string 

    */

    var $url;

 

    /**

    * Protocol

    * @var string 

    */

    var $protocol;

 

    /**

    * Username

    * @var string 

    */

    var $username;

 

    /**

    * Password

    * @var string 

    */

    var $password;

 

    /**

    * Host

    * @var string 

    */

    var $host;

 

    /**

    * Port

    * @var integer 

    */

    var $port;

 

    /**

    * Path

    * @var string 

    */

    var $path;

 

    /**

    * Query string

    * @var array 

    */

    var $querystring;

 

    /**

    * Anchor

    * @var string 

    */

    var $anchor;

 

    /**

    * Whether to use []

    * @var bool 

    */

    var $useBrackets;

 

    var $url;

    var $useBrackets;

    /**

    * PHP4 Constructor

    *

    * @see __construct()

    */

    function Net_URL($url = null, $useBrackets = true)

    {

        $this->__construct($url, $useBrackets);

    }

 

    /**

    * PHP5 Constructor

    *

    * Parses the given url and stores the various parts

    * Defaults are used in certain cases

    *

    * @param string $url         Optional URL

    * @param bool   $useBrackets Whether to use square brackets when

    *                             multiple querystrings with the same name

    *                             exist

    */

    function __construct($url = null, $useBrackets = true)

    {

        $this->url = $url;

        $ths->useBrackets = $useBrackets;

 

        $this->initialize();

    }

 

    function initialize($url = null, $useBrackets = true)

    {

        $HTTP_SERVER_VARS  = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];

 

        $this->useBrackets = $useBrackets;

        $this->url         = $url;

        $this->user        = '';

        $this->pass        = '';

        $this->host        = '';

        $this->port        = 80;

        $this->path        = '';

        $this->querystring = array();

        $this->anchor      = '';

 

        // Only use defaults if not an absolute URL given

        if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {

            $this->protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https' : 'http');

 

            /**

            * Figure out host/port

            */

            if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {

                $host = $matches[1];

                if (!empty($matches[3])) {

                    $port = $matches[3];

                } else {

                    $port = $this->getStandardPort($this->protocol);

                }

            }

 

            $this->user        = '';

            $this->pass        = '';

            $this->host        = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');

            $this->port        = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));

            $this->path        = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';

            $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;

            $this->anchor      = '';

        }

 

        // Parse the url and store the various parts

        if (!empty($url)) {

            $urlinfo = parse_url($url);

 

            // Default querystring

            $this->querystring = array();

 

            foreach ($urlinfo as $key => $value) {

                switch ($key) {

                    case 'scheme':

                        $this->protocol = $value;

                        $this->port     = $this->getStandardPort($value);

                        break;

 

                    case 'user':

                    case 'pass':

                    case 'host':

                    case 'port':

                        $this->$key = $value;

                        break;

 

                    case 'path':

                        if ($value{0} == '/') {

                            $this->path = $value;

                        } else {

                            $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);

                            $this->path = sprintf('%s/%s', $path, $value);

                        }

                        break;

 

                    case 'query':

                        $this->querystring = $this->_parseRawQueryString($value);

                        break;

 

                    case 'fragment':

                        $this->anchor = $value;

                        break;

                }

            }

        }

    }

    /**

    * Returns full url

    *

    * @return string Full url

    * @access public

    */

    function getURL()

    {

        $querystring = $this->getQueryString();

 

        $this->url = $this->protocol . '://'

                   . $this->user . (!empty($this->pass) ? ':' : '')

                   . $this->pass . (!empty($this->user) ? '@' : '')

                   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)

                   . $this->path

                   . (!empty($querystring) ? '?' . $querystring : '')

                   . (!empty($this->anchor) ? '#' . $this->anchor : '');

 

        return $this->url;

    }

 

    /**

    * Adds a querystring item

    *

    * @param  string $name       Name of item

    * @param  string $value      Value of item

    * @param  bool   $preencoded Whether value is urlencoded or not, default = not

    * @access public

    */

    function addQueryString($name, $value, $preencoded = false)

    {

        if ($this->getOption('encode_query_keys')) {

            $name = rawurlencode($name);

        }

 

        if ($preencoded) {

            $this->querystring[$name] = $value;

        } else {

            $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);

        }

    }

 

    /**

    * Removes a querystring item

    *

    * @param  string $name Name of item

    * @access public

    */

    function removeQueryString($name)

    {

        if ($this->getOption('encode_query_keys')) {

            $name = rawurlencode($name);

        }

 

        if (isset($this->querystring[$name])) {

            unset($this->querystring[$name]);

        }

    }

 

    /**

    * Sets the querystring to literally what you supply

    *

    * @param  string $querystring The querystring data. Should be of the format foo=bar&x=y etc

    * @access public

    */

    function addRawQueryString($querystring)

    {

        $this->querystring = $this->_parseRawQueryString($querystring);

    }

 

    /**

    * Returns flat querystring

    *

    * @return string Querystring

    * @access public

    */

    function getQueryString()

    {

        if (!empty($this->querystring)) {

            foreach ($this->querystring as $name => $value) {

                // Encode var name

                $name = rawurlencode($name);

 

                if (is_array($value)) {

                    foreach ($value as $k => $v) {

                        $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);

                    }

                } elseif (!is_null($value)) {

                    $querystring[] = $name . '=' . $value;

                } else {

                    $querystring[] = $name;

                }

            }

            $querystring = implode(ini_get('arg_separator.output'), $querystring);

        } else {

            $querystring = '';

        }

 

        return $querystring;

    }

 

    /**

    * Parses raw querystring and returns an array of it

    *

    * @param  string  $querystring The querystring to parse

    * @return array                An array of the querystring data

    * @access private

    */

    function _parseRawQuerystring($querystring)

    {

        $parts  = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);

        $return = array();

 

        foreach ($parts as $part) {

            if (strpos($part, '=') !== false) {

                $value = substr($part, strpos($part, '=') + 1);

                $key   = substr($part, 0, strpos($part, '='));

            } else {

                $value = null;

                $key   = $part;

            }

 

            if (!$this->getOption('encode_query_keys')) {

                $key = rawurldecode($key);

            }

 

            if (preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {

                $key = $matches[1];

                $idx = $matches[2];

 

                // Ensure is an array

                if (empty($return[$key]) || !is_array($return[$key])) {

                    $return[$key] = array();

                }

 

                // Add data

                if ($idx === '') {

                    $return[$key][] = $value;

                } else {

                    $return[$key][$idx] = $value;

                }

            } elseif (!$this->useBrackets AND !empty($return[$key])) {

                $return[$key]   = (array)$return[$key];

                $return[$key][] = $value;

            } else {

                $return[$key] = $value;

            }

        }

 

        return $return;

    }

 

    /**

    * Resolves //, ../ and ./ from a path and returns

    * the result. Eg:

    *

    * /foo/bar/../boo.php    => /foo/boo.php

    * /foo/bar/../../boo.php => /boo.php

    * /foo/bar/.././/boo.php => /foo/boo.php

    *

    * This method can also be called statically.

    *

    * @param  string $url URL path to resolve

    * @return string      The result

    */

    function resolvePath($path)

    {

        $path = explode('/', str_replace('//', '/', $path));

 

        for ($i=0; $i<count($path); $i++) {

            if ($path[$i] == '.') {

                unset($path[$i]);

                $path = array_values($path);

                $i--;

 

            } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {

                unset($path[$i]);

                unset($path[$i-1]);

                $path = array_values($path);

                $i -= 2;

 

            } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {

                unset($path[$i]);

                $path = array_values($path);

                $i--;

 

            } else {

                continue;

            }

        }

 

        return implode('/', $path);

    }

 

    /**

    * Returns the standard port number for a protocol

    *

    * @param  string  $scheme The protocol to lookup

    * @return integer         Port number or NULL if no scheme matches

    *

    * @author Philippe Jausions <Philippe.Jausions@11abacus.com>

    */

    function getStandardPort($scheme)

    {

        switch (strtolower($scheme)) {

            case 'http':    return 80;

            case 'https':   return 443;

            case 'ftp':     return 21;

            case 'imap':    return 143;

            case 'imaps':   return 993;

            case 'pop3':    return 110;

            case 'pop3s':   return 995;

            default:        return null;

       }

    }

 

    /**

    * Forces the URL to a particular protocol

    *

    * @param string  $protocol Protocol to force the URL to

    * @param integer $port     Optional port (standard port is used by default)

    */

    function setProtocol($protocol, $port = null)

    {

        $this->protocol = $protocol;

        $this->port     = is_null($port) ? $this->getStandardPort($protocol) : $port;

    }

 

    /**

     * Set an option

     *

     * This function set an option

     * to be used thorough the script.

     *

     * @access public

     * @param  string $optionName  The optionname to set

     * @param  string $value       The value of this option.

     */

    function setOption($optionName, $value)

    {

        if (!array_key_exists($optionName, $this->options)) {

            return false;

        }

 

        $this->options[$optionName] = $value;

        $this->initialize();

    }

 

    /**

     * Get an option

     *

     * This function gets an option

     * from the $this->options array

     * and return it's value.

     *

     * @access public

     * @param  string $opionName  The name of the option to retrieve

     * @see    $this->options

     */

    function getOption($optionName)

    {

        if (!isset($this->options[$optionName])) {

            return false;

        }

 

        return $this->options[$optionName];

    }

 

}

?>

Actual result:
--------------
Notice: unserialize(): Error at offset 1923 of 13660 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1923 of 13660 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1310 of 3593 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1310 of 3593 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 2382 of 60276 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 2382 of 60276 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1571 of 11167 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1571 of 11167 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1583 of 7321 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1583 of 7321 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 462 of 9294 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 462 of 9294 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1240 of 9797 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1240 of 9797 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 3483 of 13930 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 3483 of 13930 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1612 of 44976 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1612 of 44976 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 56110 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 56110 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 6421 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 6421 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 50259 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 50259 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 46297 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 46297 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 6875 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 6875 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 88 of 19268 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 88 of 19268 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 481 of 23769 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 481 of 23769 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 33146 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 33146 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 72513 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 72513 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 64562 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 64562 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 10739 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 10739 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 456 of 8112 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 456 of 8112 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 189 of 4111 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 189 of 4111 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 1446 of 87983 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 1446 of 87983 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 468 of 7335 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 468 of 7335 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 11223 of 16813 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 11223 of 16813 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707

Notice: unserialize(): Error at offset 2153 of 14786 bytes in Registry.php on line 1145

Notice: unserialize(): Error at offset 2153 of 14786 bytes in Registry.php on line 1145

Warning: in_array() expects parameter 2 to be array, boolean given in 10.php on line 707
Nothing to upgrade
1

Patches

log (last revision 2014-06-25 16:26 UTC by r dot mbiama at angosso dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-25 17:11 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-06-25 17:11 UTC] aharvey@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 09:01:27 2024 UTC