Skip to content

Commit

Permalink
PHP 7.2 support (#10)
Browse files Browse the repository at this point in the history
Fixes deprecation issues with count and each, session notices, sunrise/sunset calculation differences, numerically-named property differences, and more. Inline comments have more details.
  • Loading branch information
jaydiablo authored and aripringle committed Jan 15, 2018
1 parent b1152f5 commit ba8cf7a
Show file tree
Hide file tree
Showing 34 changed files with 273 additions and 141 deletions.
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) {
$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]) {
$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);
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) {

This comment has been minimized.

Copy link
@tavy315

tavy315 Mar 10, 2018

btw count(null) = 0

This comment has been minimized.

Copy link
@jaydiablo

jaydiablo Mar 10, 2018

Author Member

Yeah, but throws a warning in PHP 7.2: https://3v4l.org/L8ihC

$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
{
/**
* 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) {
$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)) {
$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;
}

/**
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);
}

$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);

if (!$type and $value === null) {
if ($type === null && $value === false) {
$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);
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

0 comments on commit ba8cf7a

Please sign in to comment.