Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 7.2 support #10

Merged
merged 9 commits into from
Jan 15, 2018
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ tests/Zend/Translate/Adapter/_files/zend_cache---testid
tests/TestConfiguration.php
tests/Zend/Session/_files/*
tests/Zend/Cache/zend_cache_tmp_dir_*
tests/Zend/Config/Writer/temp/*
vendor/*
composer.lock
bin/dbunit
bin/phpunit
build/*
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ script:

matrix:
allow_failures:
- php: 7.2
6 changes: 3 additions & 3 deletions demos/Zend/Mobile/Push/ApnsFeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

$apns = new Zend_Mobile_Push_Apns();
$apns->setCertificate('/path/to/provisioning-certificate.pem');

try {
$apns->connect(Zend_Mobile_Push_Apns::SERVER_FEEDBACK_SANDBOX_URI);
} catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) {
Expand All @@ -13,9 +13,9 @@
echo 'APNS Connection Error:' . $e->getMessage();
exit(1);
}

$tokens = $apns->feedback();
while(list($token, $time) = each($tokens)) {
foreach ($tokens as $token => $time) {
echo $time . "\t" . $token . PHP_EOL;
}
$apns->close();
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ try {
}

$tokens = $apns->feedback();
while(list($token, $time) = each($tokens)) {
foreach ($tokens as $token => $time) {
echo $time . "\t" . $token . PHP_EOL;
}
$apns->close();
]]></programlisting>

</sect2>

<sect2 id="zend.mobile.push.apns.message">
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Cache/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(array $options = array())
public function setDirectives($directives)
{
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
while (list($name, $value) = each($directives)) {
foreach ($directives as $name => $value) {
if (!is_string($name)) {
Zend_Cache::throwException("Incorrect option name : $name");
}
Expand Down
14 changes: 8 additions & 6 deletions library/Zend/Config/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function __construct($yaml, $section = null, $options = false)
if (!isset($config[$sectionName])) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception(sprintf(
'Section "%s" cannot be found',
'Section "%s" cannot be found',
implode(' ', (array)$section)
));
}
Expand All @@ -214,7 +214,7 @@ public function __construct($yaml, $section = null, $options = false)
if (!isset($config[$section])) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception(sprintf(
'Section "%s" cannot be found',
'Section "%s" cannot be found',
implode(' ', (array)$section)
));
}
Expand Down Expand Up @@ -289,8 +289,10 @@ protected static function _decodeYaml($currentIndent, &$lines)
{
$config = array();
$inIndent = false;
while (list($n, $line) = each($lines)) {
$lineno = $n + 1;
while (key($lines) !== null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simple foreach was not possible here because the position of the array pointer is important (both internal to this function (due to the prev used below) and external to this function (since $lines is passed by reference)).

$line = current($lines);
$lineno = key($lines) + 1;
next($lines);

$line = rtrim(preg_replace("/#.*$/", "", $line));
if (strlen($line) == 0) {
Expand Down Expand Up @@ -363,10 +365,10 @@ protected static function _parseValue($value)

// remove quotes from string.
if ('"' == $value['0']) {
if ('"' == $value[count($value) -1]) {
if ('"' == $value[strlen($value) -1]) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably a long-standing bug, since count in this case would always return 1 on a string, so this would always be $value[0] which is the same as the condition above.

$value = substr($value, 1, -1);
}
} elseif ('\'' == $value['0'] && '\'' == $value[count($value) -1]) {
} elseif ('\'' == $value['0'] && '\'' == $value[strlen($value) -1]) {
$value = strtr($value, array("''" => "'", "'" => ''));
}

Expand Down
8 changes: 4 additions & 4 deletions library/Zend/Date/DateObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ protected function date($format, $timestamp = null, $gmt = false)

if (abs($timestamp) <= 0x7FFFFFFF) {
// See ZF-11992
// "o" will sometimes resolve to the previous year (see
// http://php.net/date ; it's part of the ISO 8601
// standard). However, this is not desired, so replacing
// all occurrences of "o" not preceded by a backslash
// "o" will sometimes resolve to the previous year (see
// http://php.net/date ; it's part of the ISO 8601
// standard). However, this is not desired, so replacing
// all occurrences of "o" not preceded by a backslash
// with "Y"
$format = preg_replace('/(?<!\\\\)o/', 'Y', $format);
$result = ($gmt) ? @gmdate($format, $timestamp) : @date($format, $timestamp);
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Db/Table/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,13 @@ public function find()
$whereList = array();
$numberTerms = 0;
foreach ($args as $keyPosition => $keyValues) {
$keyValuesCount = count($keyValues);
// Coerce the values to an array.
// Don't simply typecast to array, because the values
// might be Zend_Db_Expr objects.
if (!is_array($keyValues)) {
$keyValues = array($keyValues);
}
$keyValuesCount = count($keyValues);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seemed safe to move this down a bit, so count is always executed on an array.

if ($numberTerms == 0) {
$numberTerms = $keyValuesCount;
} else if ($keyValuesCount != $numberTerms) {
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Feed/Reader/Entry/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function getAuthors()
);
}

if (count($authors) == 0) {
if ($authors !== null && count($authors) == 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the tests $authors would sometimes be null here, which count returns 0 on.

$authors = null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Feed/Reader/Feed/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function getAuthors()
);
}

if (count($authors) == 0) {
if ($authors !== null && count($authors) == 0) {
$authors = null;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public static function getAllCapabilities(TeraWurfl $wurflObj)
if (!is_array($group)) {
continue;
}
while (list ($key, $value) = each($group)) {
foreach ($group as $key => $value) {
if (is_bool($value)) {
// to have the same type than the official WURFL API
$features[$key] = ($value ? 'true' : 'false');
Expand Down
21 changes: 13 additions & 8 deletions library/Zend/Mail/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface
class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface, Countable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests run count on this object, so added the Countable interface. It doesn't seem to happen in the code base at all otherwise.

The specific test doing this was counting the object to make sure there were no parts.

{
/**
* headers of part as array
Expand Down Expand Up @@ -96,10 +96,10 @@ class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface
* @var int
*/
protected $_messageNum = 0;

/**
* Class to use when creating message parts
* @var string
* @var string
*/
protected $_partClass;

Expand Down Expand Up @@ -138,7 +138,7 @@ public function __construct(array $params)
$this->_mail = $params['handler'];
$this->_messageNum = $params['id'];
}

if (isset($params['partclass'])) {
$this->setPartClass($params['partclass']);
}
Expand All @@ -162,7 +162,7 @@ public function __construct(array $params)
}
}
}

/**
* Set name pf class used to encapsulate message parts
* @param string $class
Expand All @@ -184,14 +184,14 @@ public function setPartClass($class)
require_once 'Zend/Mail/Exception.php';
throw new Zend_Mail_Exception("Class '{$class}' must implement Zend_Mail_Part_Interface");
}

$this->_partClass = $class;
return $this;
}

/**
* Retrieve the class name used to encapsulate message parts
* @return string
* @return string
*/
public function getPartClass()
{
Expand Down Expand Up @@ -579,6 +579,11 @@ public function rewind()
$this->_iterationPos = 1;
}

public function count()
{
return $this->countParts();
}

/**
* Ensure headers do not contain invalid characters
*
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Oauth/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(
if ($response !== null) {
$this->_response = $response;
$params = $this->_parseParameters($response);
if (count($params) > 0) {
if ($params !== null && count($params) > 0) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$params can be null in some cases.

$this->setParams($params);
}
}
Expand Down
10 changes: 6 additions & 4 deletions library/Zend/Rest/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ public function match($request, $partial = false)
/**
* Assembles user submitted parameters forming a URL path defined by this route
*
* @param array $data An array of variable and value pairs used as parameters
* @param bool $reset Weither to reset the current params
* @param bool $encode Weither to return urlencoded string
* @param array $data An array of variable and value pairs used as parameters
* @param bool $reset Weither to reset the current params
* @param bool $encode Weither to return urlencoded string
* @param bool $partial
*
* @return string Route path with user submitted parameters
*/
public function assemble($data = array(), $reset = false, $encode = true)
public function assemble($data = array(), $reset = false, $encode = true, $partial = false)
{
if (!$this->_keysSet) {
if (null === $this->_request) {
Expand Down
6 changes: 5 additions & 1 deletion library/Zend/Test/DbStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ public function setRowCount($rowCount)
*/
public function append($row)
{
$this->_columnCount = count($row);
if (!is_array($row)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$row, in the tests at least, can be just a string, which count returns 1 for. This should act the same, just avoid the warning thrown by php 7.2+.

$this->_columnCount = 1;
} else {
$this->_columnCount = count($row);
}
$this->_fetchStack[] = $row;
}

Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Tool/Project/Profile/Resource/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function valid()
*/
public function hasChildren()
{
return (count($this->_subResources > 0)) ? true : false;
return (count($this->_subResources) > 0) ? true : false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a type-o, but since it would have been counting true or false, behavior doesn't change.

}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Validate/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ private function _validateMXRecords()

//decode IDN domain name if possible
if (function_exists('idn_to_ascii')) {
$hostname = idn_to_ascii($this->_hostname);
$hostname = idn_to_ascii($this->_hostname, 0, INTL_IDNA_VARIANT_UTS46);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a test throwing a deprecation notice (but not failing) because of this.

The default constant used to this function (if not specified) is INTL_IDNA_VARIANT_2003 which was deprecated in php 7.2.0.

INTL_IDNA_VARIANT_2003 has been deprecated; use INTL_IDNA_VARIANT_UTS46 instead.

The INTL_IDNA_VARIANT_UTS46 constant was added in php 5.4. So this will break now for php 5.4 (but the lowest we're testing against is 5.6 since everything else is EOL).

}

$result = getmxrr($hostname, $mxHosts);
Expand Down
2 changes: 1 addition & 1 deletion library/Zend/Validate/File/Upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function getFiles($file = null)
*/
public function setFiles($files = array())
{
if (count($files) === 0) {
if ($files === null || count($files) === 0) {
$this->_files = $_FILES;
} else {
$this->_files = $files;
Expand Down
10 changes: 7 additions & 3 deletions library/Zend/XmlRpc/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,17 @@ protected static function _createSimpleXMLElement(&$xml)
*/
protected static function _extractTypeAndValue(SimpleXMLElement $xml, &$type, &$value)
{
list($type, $value) = each($xml);
$type = key($xml);
$value = current($xml);
next($xml);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should mimic the old list ... each syntax (including moving the array pointer).


if (!$type and $value === null) {
if ($type === null && $value === false) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the two values that would be set if key and current above were at the end of the array (or the array was empty).

$namespaces = array('ex' => 'http://ws.apache.org/xmlrpc/namespaces/extensions');
foreach ($namespaces as $namespaceName => $namespaceUri) {
$namespaceXml = $xml->children($namespaceUri);
list($type, $value) = each($namespaceXml);
$type = key($namespaceXml);
$value = current($namespaceXml);
next($namespaceXml);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above.

if ($type !== null) {
$type = $namespaceName . ':' . $type;
break;
Expand Down
12 changes: 9 additions & 3 deletions tests/Zend/Amf/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,22 @@ public function testAmf0MixedArrayParameterDeserializedToNativePhpObject()
$myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/mixedArrayAmf0Request.bin');
// send the mock object request to be deserialized
$this->_request->initialize($myRequest);
// Make sure that no headers where recieved
// Make sure that no headers were recieved
$this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
// Make sure that the message body was set after deserialization
$this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
$bodies = $this->_request->getAmfBodies();
$this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
$data = $bodies[0]->getData();
// Make sure that the string was deserialized properly and check its value
$this->assertTrue(array_key_exists(1, $data[0]));
// In PHP versions less than 7, get_object_vars doesn't return numerical
// keys. In PHP 7.2+ array_key_exists on this particular object returns false
// https://3v4l.org/ui8Fm
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
$this->assertTrue(array_key_exists(1, get_object_vars($data[0])));
} else {
$this->assertTrue(array_key_exists(1, $data[0]));
}
$this->assertEquals('two', $data[0]->two);
}

Expand Down Expand Up @@ -666,4 +673,3 @@ public function testAmf0CredentialsInHeader()
if (PHPUnit_MAIN_METHOD == 'Zend_Amf_RequestTest::main') {
Zend_Amf_RequestTest::main();
}

4 changes: 2 additions & 2 deletions tests/Zend/Controller/Router/Route/ChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ public function getVersion()
return 2;
}

public function assemble($data = array(), $reset = false, $encode = false)
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{}

public static function getInstance(Zend_Config $config)
Expand All @@ -1040,7 +1040,7 @@ public function getVersion()
return 2;
}

public function assemble($data = array(), $reset = false, $encode = false)
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
{}

public static function getInstance(Zend_Config $config)
Expand Down
Loading