Skip to content

Commit ba8cf7a

Browse files
jaydiabloaripringle
authored andcommitted
PHP 7.2 support (#10)
Fixes deprecation issues with count and each, session notices, sunrise/sunset calculation differences, numerically-named property differences, and more. Inline comments have more details.
1 parent b1152f5 commit ba8cf7a

File tree

34 files changed

+273
-141
lines changed

34 files changed

+273
-141
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ tests/Zend/Translate/Adapter/_files/zend_cache---testid
1010
tests/TestConfiguration.php
1111
tests/Zend/Session/_files/*
1212
tests/Zend/Cache/zend_cache_tmp_dir_*
13+
tests/Zend/Config/Writer/temp/*
1314
vendor/*
1415
composer.lock
1516
bin/dbunit
1617
bin/phpunit
18+
build/*

.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ script:
3535

3636
matrix:
3737
allow_failures:
38-
- php: 7.2

demos/Zend/Mobile/Push/ApnsFeedback.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
$apns = new Zend_Mobile_Push_Apns();
55
$apns->setCertificate('/path/to/provisioning-certificate.pem');
6-
6+
77
try {
88
$apns->connect(Zend_Mobile_Push_Apns::SERVER_FEEDBACK_SANDBOX_URI);
99
} catch (Zend_Mobile_Push_Exception_ServerUnavailable $e) {
@@ -13,9 +13,9 @@
1313
echo 'APNS Connection Error:' . $e->getMessage();
1414
exit(1);
1515
}
16-
16+
1717
$tokens = $apns->feedback();
18-
while(list($token, $time) = each($tokens)) {
18+
foreach ($tokens as $token => $time) {
1919
echo $time . "\t" . $token . PHP_EOL;
2020
}
2121
$apns->close();

documentation/manual/en/module_specs/Zend_Mobile_Push-Apns.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ try {
152152
}
153153
154154
$tokens = $apns->feedback();
155-
while(list($token, $time) = each($tokens)) {
155+
foreach ($tokens as $token => $time) {
156156
echo $time . "\t" . $token . PHP_EOL;
157157
}
158158
$apns->close();
159159
]]></programlisting>
160-
160+
161161
</sect2>
162162

163163
<sect2 id="zend.mobile.push.apns.message">

library/Zend/Cache/Backend.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function __construct(array $options = array())
7676
public function setDirectives($directives)
7777
{
7878
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
79-
while (list($name, $value) = each($directives)) {
79+
foreach ($directives as $name => $value) {
8080
if (!is_string($name)) {
8181
Zend_Cache::throwException("Incorrect option name : $name");
8282
}

library/Zend/Config/Yaml.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function __construct($yaml, $section = null, $options = false)
202202
if (!isset($config[$sectionName])) {
203203
require_once 'Zend/Config/Exception.php';
204204
throw new Zend_Config_Exception(sprintf(
205-
'Section "%s" cannot be found',
205+
'Section "%s" cannot be found',
206206
implode(' ', (array)$section)
207207
));
208208
}
@@ -214,7 +214,7 @@ public function __construct($yaml, $section = null, $options = false)
214214
if (!isset($config[$section])) {
215215
require_once 'Zend/Config/Exception.php';
216216
throw new Zend_Config_Exception(sprintf(
217-
'Section "%s" cannot be found',
217+
'Section "%s" cannot be found',
218218
implode(' ', (array)$section)
219219
));
220220
}
@@ -289,8 +289,10 @@ protected static function _decodeYaml($currentIndent, &$lines)
289289
{
290290
$config = array();
291291
$inIndent = false;
292-
while (list($n, $line) = each($lines)) {
293-
$lineno = $n + 1;
292+
while (key($lines) !== null) {
293+
$line = current($lines);
294+
$lineno = key($lines) + 1;
295+
next($lines);
294296

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

364366
// remove quotes from string.
365367
if ('"' == $value['0']) {
366-
if ('"' == $value[count($value) -1]) {
368+
if ('"' == $value[strlen($value) -1]) {
367369
$value = substr($value, 1, -1);
368370
}
369-
} elseif ('\'' == $value['0'] && '\'' == $value[count($value) -1]) {
371+
} elseif ('\'' == $value['0'] && '\'' == $value[strlen($value) -1]) {
370372
$value = strtr($value, array("''" => "'", "'" => ''));
371373
}
372374

library/Zend/Date/DateObject.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ protected function date($format, $timestamp = null, $gmt = false)
313313

314314
if (abs($timestamp) <= 0x7FFFFFFF) {
315315
// See ZF-11992
316-
// "o" will sometimes resolve to the previous year (see
317-
// http://php.net/date ; it's part of the ISO 8601
318-
// standard). However, this is not desired, so replacing
319-
// all occurrences of "o" not preceded by a backslash
316+
// "o" will sometimes resolve to the previous year (see
317+
// http://php.net/date ; it's part of the ISO 8601
318+
// standard). However, this is not desired, so replacing
319+
// all occurrences of "o" not preceded by a backslash
320320
// with "Y"
321321
$format = preg_replace('/(?<!\\\\)o/', 'Y', $format);
322322
$result = ($gmt) ? @gmdate($format, $timestamp) : @date($format, $timestamp);

library/Zend/Db/Table/Abstract.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1304,13 +1304,13 @@ public function find()
13041304
$whereList = array();
13051305
$numberTerms = 0;
13061306
foreach ($args as $keyPosition => $keyValues) {
1307-
$keyValuesCount = count($keyValues);
13081307
// Coerce the values to an array.
13091308
// Don't simply typecast to array, because the values
13101309
// might be Zend_Db_Expr objects.
13111310
if (!is_array($keyValues)) {
13121311
$keyValues = array($keyValues);
13131312
}
1313+
$keyValuesCount = count($keyValues);
13141314
if ($numberTerms == 0) {
13151315
$numberTerms = $keyValuesCount;
13161316
} else if ($keyValuesCount != $numberTerms) {

library/Zend/Feed/Reader/Entry/Rss.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function getAuthors()
201201
);
202202
}
203203

204-
if (count($authors) == 0) {
204+
if ($authors !== null && count($authors) == 0) {
205205
$authors = null;
206206
}
207207

library/Zend/Feed/Reader/Feed/Rss.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function getAuthors()
151151
);
152152
}
153153

154-
if (count($authors) == 0) {
154+
if ($authors !== null && count($authors) == 0) {
155155
$authors = null;
156156
}
157157

library/Zend/Http/UserAgent/Features/Adapter/TeraWurfl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static function getAllCapabilities(TeraWurfl $wurflObj)
8888
if (!is_array($group)) {
8989
continue;
9090
}
91-
while (list ($key, $value) = each($group)) {
91+
foreach ($group as $key => $value) {
9292
if (is_bool($value)) {
9393
// to have the same type than the official WURFL API
9494
$features[$key] = ($value ? 'true' : 'false');

library/Zend/Mail/Part.php

+13-8
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
4848
* @license http://framework.zend.com/license/new-bsd New BSD License
4949
*/
50-
class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface
50+
class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface, Countable
5151
{
5252
/**
5353
* headers of part as array
@@ -96,10 +96,10 @@ class Zend_Mail_Part implements RecursiveIterator, Zend_Mail_Part_Interface
9696
* @var int
9797
*/
9898
protected $_messageNum = 0;
99-
99+
100100
/**
101101
* Class to use when creating message parts
102-
* @var string
102+
* @var string
103103
*/
104104
protected $_partClass;
105105

@@ -138,7 +138,7 @@ public function __construct(array $params)
138138
$this->_mail = $params['handler'];
139139
$this->_messageNum = $params['id'];
140140
}
141-
141+
142142
if (isset($params['partclass'])) {
143143
$this->setPartClass($params['partclass']);
144144
}
@@ -162,7 +162,7 @@ public function __construct(array $params)
162162
}
163163
}
164164
}
165-
165+
166166
/**
167167
* Set name pf class used to encapsulate message parts
168168
* @param string $class
@@ -184,14 +184,14 @@ public function setPartClass($class)
184184
require_once 'Zend/Mail/Exception.php';
185185
throw new Zend_Mail_Exception("Class '{$class}' must implement Zend_Mail_Part_Interface");
186186
}
187-
187+
188188
$this->_partClass = $class;
189189
return $this;
190190
}
191-
191+
192192
/**
193193
* Retrieve the class name used to encapsulate message parts
194-
* @return string
194+
* @return string
195195
*/
196196
public function getPartClass()
197197
{
@@ -579,6 +579,11 @@ public function rewind()
579579
$this->_iterationPos = 1;
580580
}
581581

582+
public function count()
583+
{
584+
return $this->countParts();
585+
}
586+
582587
/**
583588
* Ensure headers do not contain invalid characters
584589
*

library/Zend/Oauth/Token.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(
7171
if ($response !== null) {
7272
$this->_response = $response;
7373
$params = $this->_parseParameters($response);
74-
if (count($params) > 0) {
74+
if ($params !== null && count($params) > 0) {
7575
$this->setParams($params);
7676
}
7777
}

library/Zend/Rest/Route.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ public function match($request, $partial = false)
236236
/**
237237
* Assembles user submitted parameters forming a URL path defined by this route
238238
*
239-
* @param array $data An array of variable and value pairs used as parameters
240-
* @param bool $reset Weither to reset the current params
241-
* @param bool $encode Weither to return urlencoded string
239+
* @param array $data An array of variable and value pairs used as parameters
240+
* @param bool $reset Weither to reset the current params
241+
* @param bool $encode Weither to return urlencoded string
242+
* @param bool $partial
243+
*
242244
* @return string Route path with user submitted parameters
243245
*/
244-
public function assemble($data = array(), $reset = false, $encode = true)
246+
public function assemble($data = array(), $reset = false, $encode = true, $partial = false)
245247
{
246248
if (!$this->_keysSet) {
247249
if (null === $this->_request) {

library/Zend/Test/DbStatement.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ public function setRowCount($rowCount)
140140
*/
141141
public function append($row)
142142
{
143-
$this->_columnCount = count($row);
143+
if (!is_array($row)) {
144+
$this->_columnCount = 1;
145+
} else {
146+
$this->_columnCount = count($row);
147+
}
144148
$this->_fetchStack[] = $row;
145149
}
146150

library/Zend/Tool/Project/Profile/Resource/Container.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function valid()
383383
*/
384384
public function hasChildren()
385385
{
386-
return (count($this->_subResources > 0)) ? true : false;
386+
return (count($this->_subResources) > 0) ? true : false;
387387
}
388388

389389
/**

library/Zend/Validate/EmailAddress.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ private function _validateMXRecords()
453453

454454
//decode IDN domain name if possible
455455
if (function_exists('idn_to_ascii')) {
456-
$hostname = idn_to_ascii($this->_hostname);
456+
$hostname = idn_to_ascii($this->_hostname, 0, INTL_IDNA_VARIANT_UTS46);
457457
}
458458

459459
$result = getmxrr($hostname, $mxHosts);

library/Zend/Validate/File/Upload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getFiles($file = null)
129129
*/
130130
public function setFiles($files = array())
131131
{
132-
if (count($files) === 0) {
132+
if ($files === null || count($files) === 0) {
133133
$this->_files = $_FILES;
134134
} else {
135135
$this->_files = $files;

library/Zend/XmlRpc/Value.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,17 @@ protected static function _createSimpleXMLElement(&$xml)
486486
*/
487487
protected static function _extractTypeAndValue(SimpleXMLElement $xml, &$type, &$value)
488488
{
489-
list($type, $value) = each($xml);
489+
$type = key($xml);
490+
$value = current($xml);
491+
next($xml);
490492

491-
if (!$type and $value === null) {
493+
if ($type === null && $value === false) {
492494
$namespaces = array('ex' => 'http://ws.apache.org/xmlrpc/namespaces/extensions');
493495
foreach ($namespaces as $namespaceName => $namespaceUri) {
494496
$namespaceXml = $xml->children($namespaceUri);
495-
list($type, $value) = each($namespaceXml);
497+
$type = key($namespaceXml);
498+
$value = current($namespaceXml);
499+
next($namespaceXml);
496500
if ($type !== null) {
497501
$type = $namespaceName . ':' . $type;
498502
break;

tests/Zend/Amf/RequestTest.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,22 @@ public function testAmf0MixedArrayParameterDeserializedToNativePhpObject()
425425
$myRequest = file_get_contents(dirname(__FILE__) .'/Request/mock/mixedArrayAmf0Request.bin');
426426
// send the mock object request to be deserialized
427427
$this->_request->initialize($myRequest);
428-
// Make sure that no headers where recieved
428+
// Make sure that no headers were recieved
429429
$this->assertEquals(0 , sizeof($this->_request->getAmfHeaders()));
430430
// Make sure that the message body was set after deserialization
431431
$this->assertEquals(1, sizeof($this->_request->getAmfBodies()));
432432
$bodies = $this->_request->getAmfBodies();
433433
$this->assertTrue($bodies[0] instanceof Zend_Amf_Value_MessageBody);
434434
$data = $bodies[0]->getData();
435435
// Make sure that the string was deserialized properly and check its value
436-
$this->assertTrue(array_key_exists(1, $data[0]));
436+
// In PHP versions less than 7, get_object_vars doesn't return numerical
437+
// keys. In PHP 7.2+ array_key_exists on this particular object returns false
438+
// https://3v4l.org/ui8Fm
439+
if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
440+
$this->assertTrue(array_key_exists(1, get_object_vars($data[0])));
441+
} else {
442+
$this->assertTrue(array_key_exists(1, $data[0]));
443+
}
437444
$this->assertEquals('two', $data[0]->two);
438445
}
439446

@@ -666,4 +673,3 @@ public function testAmf0CredentialsInHeader()
666673
if (PHPUnit_MAIN_METHOD == 'Zend_Amf_RequestTest::main') {
667674
Zend_Amf_RequestTest::main();
668675
}
669-

tests/Zend/Controller/Router/Route/ChainTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ public function getVersion()
10151015
return 2;
10161016
}
10171017

1018-
public function assemble($data = array(), $reset = false, $encode = false)
1018+
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
10191019
{}
10201020

10211021
public static function getInstance(Zend_Config $config)
@@ -1040,7 +1040,7 @@ public function getVersion()
10401040
return 2;
10411041
}
10421042

1043-
public function assemble($data = array(), $reset = false, $encode = false)
1043+
public function assemble($data = array(), $reset = false, $encode = false, $partial = false)
10441044
{}
10451045

10461046
public static function getInstance(Zend_Config $config)

0 commit comments

Comments
 (0)