Skip to content

Commit c41c870

Browse files
committed
PHP 8.0 > fread()/count() behavior
ValueError: fread(): Argument #2 ($length) must be greater than 0 TypeError: count(): Argument #1 ($value) must be of type Countable|array Foo Given Use Symfony Polyfill symfony/polyfill@d330c00 TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given Do not use Symfony pollyfill, is_array is enought
1 parent a320547 commit c41c870

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

lib/cache/sfFileCache.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ protected function read($path, $type = self::READ_DATA)
256256
fseek($fp, 0, SEEK_END);
257257
$length = ftell($fp) - 24;
258258
fseek($fp, 24);
259-
$data[self::READ_DATA] = @fread($fp, $length);
259+
if($length > 0) {
260+
$data[self::READ_DATA] = @fread($fp, $length);
261+
} else {
262+
$data[self::READ_DATA] = '';
263+
}
260264
}
261265
}
262266
else

lib/escaper/sfOutputEscaperObjectDecorator.class.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,17 @@ public function __isset($key)
111111
/**
112112
* Returns the size of the object if it implements Countable (is required by the Countable interface).
113113
*
114-
* It returns 1 if other cases (which is the default PHP behavior in such a case).
114+
* It returns 1 if other cases (which was the default PHP behavior in such a case before php 7.3).
115115
*
116116
* @return int The size of the object
117117
*/
118118
#[\ReturnTypeWillChange]
119119
public function count()
120120
{
121-
return count($this->value);
121+
// See https://github.com/symfony/polyfill/commit/d330c0094a47d8edceeea1ed553d6e08215a9fc2
122+
if(is_array($this->value) || $this->value instanceof Countable || $this->value instanceof ResourceBundle || $this->value instanceof SimpleXmlElement) {
123+
return count($this->value);
124+
}
125+
return 1;
122126
}
123127
}

lib/i18n/sfCultureInfo.class.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ class sfCultureInfo
9292
* @var sfNumberFormatInfo
9393
*/
9494
protected $numberFormat;
95-
95+
9696
/**
9797
* A list of properties that are accessable/writable.
9898
* @var array
99-
*/
99+
*/
100100
protected $properties = array();
101101

102102
/**
@@ -191,9 +191,9 @@ public function __set($name, $value)
191191
}
192192

193193
/**
194-
* Initializes a new instance of the sfCultureInfo class based on the
194+
* Initializes a new instance of the sfCultureInfo class based on the
195195
* culture specified by name. E.g. <code>new sfCultureInfo('en_AU');</code>
196-
* The culture indentifier must be of the form
196+
* The culture indentifier must be of the form
197197
* "<language>_(country/region/variant)".
198198
*
199199
* @param string $culture a culture name, e.g. "en_AU".
@@ -323,7 +323,7 @@ protected function loadCultureData($culture)
323323
* this function.
324324
*
325325
* @param string $filename the ICU data filename
326-
* @return array ICU data
326+
* @return array ICU data
327327
*/
328328
protected function &getData($filename)
329329
{
@@ -347,7 +347,7 @@ protected function &getData($filename)
347347
* Use merge=true to return the ICU including the parent culture.
348348
* E.g. The currency data for a variant, say "en_AU" contains one
349349
* entry, the currency for AUD, the other currency data are stored
350-
* in the "en" data file. Thus to retrieve all the data regarding
350+
* in the "en" data file. Thus to retrieve all the data regarding
351351
* currency for "en_AU", you need to use findInfo("Currencies,true);.
352352
*
353353
* @param string $path the data you want to find.
@@ -429,9 +429,9 @@ protected function searchArray($info, $path = '/')
429429
}
430430
}
431431
}
432-
432+
433433
/**
434-
* Gets the culture name in the format
434+
* Gets the culture name in the format
435435
* "<languagecode2>_(country/regioncode2)".
436436
*
437437
* @return string culture name.
@@ -516,7 +516,7 @@ public function getEnglishName()
516516
$culture = $this->getInvariantCulture();
517517

518518
$language = $culture->findInfo("Languages/{$lang}");
519-
if (count($language) == 0)
519+
if (is_array($language) && count($language) == 0)
520520
{
521521
return $this->culture;
522522
}
@@ -547,7 +547,7 @@ static function getInvariantCulture()
547547
}
548548

549549
/**
550-
* Gets a value indicating whether the current sfCultureInfo
550+
* Gets a value indicating whether the current sfCultureInfo
551551
* represents a neutral culture. Returns true if the culture
552552
* only contains two characters.
553553
*
@@ -590,7 +590,7 @@ public function setNumberFormat($numberFormat)
590590
}
591591

592592
/**
593-
* Gets the sfCultureInfo that represents the parent culture of the
593+
* Gets the sfCultureInfo that represents the parent culture of the
594594
* current sfCultureInfo
595595
*
596596
* @return sfCultureInfo parent culture information.
@@ -606,14 +606,14 @@ public function getParent()
606606
}
607607

608608
/**
609-
* Gets the list of supported cultures filtered by the specified
609+
* Gets the list of supported cultures filtered by the specified
610610
* culture type. This is an EXPENSIVE function, it needs to traverse
611611
* a list of ICU files in the data directory.
612612
* This function can be called statically.
613613
*
614614
* @param int $type culture type, sfCultureInfo::ALL, sfCultureInfo::NEUTRAL
615615
* or sfCultureInfo::SPECIFIC.
616-
* @return array list of culture information available.
616+
* @return array list of culture information available.
617617
*/
618618
static function getCultures($type = sfCultureInfo::ALL)
619619
{
@@ -719,7 +719,7 @@ public function getLanguage($code)
719719
*
720720
* @param array $countries An array of countries used to restrict the returned array (null by default, which means all countries)
721721
*
722-
* @return array a list of localized country names.
722+
* @return array a list of localized country names.
723723
*/
724724
public function getCountries($countries = null)
725725
{

0 commit comments

Comments
 (0)