1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Add “#[\ReturnTypeWillChange]” comments to all InteratorAggregate, Countable and PDOStatement interface classes to stop PHP 8.1 notices per https://php.watch/versions/8.1/internal-method-return-types and processwire/processwire-issues#1467 ... someday when all PHP 5.x support can be dropped these will be converted to PHP 7.1+ return types

This commit is contained in:
Ryan Cramer
2021-12-31 09:19:09 -05:00
parent bca50abb48
commit ee64e114f2
23 changed files with 82 additions and 13 deletions

View File

@@ -224,6 +224,7 @@ class Fieldtypes extends WireArray {
protected function filterData($selectors, $not = false) { $this->preload(); return parent::filterData($selectors, $not); } protected function filterData($selectors, $not = false) { $this->preload(); return parent::filterData($selectors, $not); }
public function makeCopy() { $this->preload(); return parent::makeCopy(); } public function makeCopy() { $this->preload(); return parent::makeCopy(); }
public function makeNew() { $this->preload(); return parent::makeNew(); } public function makeNew() { $this->preload(); return parent::makeNew(); }
#[\ReturnTypeWillChange]
public function getIterator() { $this->preload(); return parent::getIterator(); } public function getIterator() { $this->preload(); return parent::getIterator(); }
public function getNext($item, $strict = true) { $this->preload(); return parent::getNext($item, $strict); } public function getNext($item, $strict = true) { $this->preload(); return parent::getNext($item, $strict); }
public function getPrev($item, $strict = true) { $this->preload(); return parent::getPrev($item, $strict); } public function getPrev($item, $strict = true) { $this->preload(); return parent::getPrev($item, $strict); }

View File

@@ -81,6 +81,7 @@ class FilenameArray implements \IteratorAggregate, \Countable {
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->data); return new \ArrayObject($this->data);
} }
@@ -138,6 +139,7 @@ class FilenameArray implements \IteratorAggregate, \Countable {
* @return int * @return int
* *
*/ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->data); return count($this->data);
} }

View File

@@ -130,6 +130,7 @@ class Fuel implements \IteratorAggregate {
return isset($this->data[$key]) ? $this->data[$key] : null; return isset($this->data[$key]) ? $this->data[$key] : null;
} }
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->data); return new \ArrayObject($this->data);
} }

View File

@@ -1372,6 +1372,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
* @return InputfieldsArray * @return InputfieldsArray
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return $this->children(); return $this->children();
} }
@@ -1384,6 +1385,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
* @return int * @return int
* *
*/ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->children()); return count($this->children());
} }

View File

@@ -2922,6 +2922,7 @@ class Page extends WireData implements \Countable, WireMatchable {
* @see Page::hasChildren(), Page::numChildren() * @see Page::hasChildren(), Page::numChildren()
* *
*/ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
if($this->outputFormatting) return $this->numChildren(true); if($this->outputFormatting) return $this->numChildren(true);
return $this->numChildren(false); return $this->numChildren(false);
@@ -2945,6 +2946,7 @@ class Page extends WireData implements \Countable, WireMatchable {
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
$a = $this->settings; $a = $this->settings;
$template = $this->template(); $template = $this->template();

View File

@@ -597,6 +597,7 @@ class PageArray extends PaginatedArray implements WirePaginatable {
* @return Page[]|\ArrayObject|PageArrayIterator * @return Page[]|\ArrayObject|PageArrayIterator
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
if($this->lazyLoad) return new PageArrayIterator($this->data, $this->finderOptions); if($this->lazyLoad) return new PageArrayIterator($this->data, $this->finderOptions);
return parent::getIterator(); return parent::getIterator();

View File

@@ -862,7 +862,7 @@ class PageTraversal {
if($options === true || (is_array($options) && !empty($options['http']))) { if($options === true || (is_array($options) && !empty($options['http']))) {
if(strpos($url, '://') === false) { if(strpos($url, '://') === false) {
$url = ($https ? 'https://' : 'http://') . $config->httpHost . $url; $url = ($https || $config->https ? 'https://' : 'http://') . $config->httpHost . $url;
} }
} }

View File

@@ -45,6 +45,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
parent::__construct(); parent::__construct();
} }
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return $this->find(); return $this->find();
} }
@@ -58,6 +59,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
* @return int * @return int
* *
*/ */
#[\ReturnTypeWillChange]
public function count($options = array()) { public function count($options = array()) {
if($this->variations) { if($this->variations) {
$count = $this->variations->count(); $count = $this->variations->count();
@@ -227,9 +229,26 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
); );
foreach($this->pageimage->extras() as $name => $extra) { foreach($this->pageimage->extras() as $name => $extra) {
if(!$extra->exists()) continue;
$info["{$name}Url"] = $extra->url(false); if($extra->exists()) {
$info["{$name}Path"] = $extra->filename(); $info["{$name}Url"] = $extra->url(false);
$info["{$name}Path"] = $extra->filename();
continue;
}
$f = "$basename.$extra->ext"; // useSrcExt, i.e. file.png.webp
if(is_readable($this->pagefiles->path . $f)) {
$info["{$name}Url"] = $this->pagefiles->url . $f;
$info["{$name}Path"] = $this->pagefiles->path . $f;
continue;
}
$f = basename($basename, '.' . $this->pageimage->ext()) . ".$extra->ext";
if(is_readable($this->pagefiles->path . $f)) {
$info["{$name}Url"] = $this->pagefiles->url . $f;
$info["{$name}Path"] = $this->pagefiles->path . $f;
continue;
}
} }
if(empty($info['crop'])) { if(empty($info['crop'])) {

View File

@@ -432,7 +432,7 @@ class PagesPathFinder extends Wire {
if(empty($result['language']['name'])) $this->setResultLanguage($language); if(empty($result['language']['name'])) $this->setResultLanguage($language);
} }
if(!isset($namesByLanguage[$language->name])) $namesByLanguage[$language->name] = array(); if(!isset($namesByLanguage[$language->name])) $namesByLanguage[$language->name] = array();
$namesByLanguage[$language->name][] = strlen($nameLanguage) ? $nameLanguage : $nameDefault; $namesByLanguage[$language->name][] = strlen("$nameLanguage") ? $nameLanguage : $nameDefault;
} }
} }
@@ -1348,6 +1348,7 @@ class PagesPathFinder extends Wire {
* *
*/ */
protected function pageNameToUTF8($name) { protected function pageNameToUTF8($name) {
$name = (string) $name;
if($this->pageNameCharset !== 'UTF8') return $name; if($this->pageNameCharset !== 'UTF8') return $name;
if(strpos($name, 'xn-') !== 0) return $name; if(strpos($name, 'xn-') !== 0) return $name;
return $this->wire()->sanitizer->pageName($name, Sanitizer::toUTF8); return $this->wire()->sanitizer->pageName($name, Sanitizer::toUTF8);

View File

@@ -494,6 +494,7 @@ class PagesType extends Wire implements \IteratorAggregate, \Countable {
* #pw-internal * #pw-internal
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return $this->find("id>0, sort=name", array( return $this->find("id>0, sort=name", array(
'caller' => $this->className() . '.getIterator()' 'caller' => $this->className() . '.getIterator()'

View File

@@ -256,6 +256,7 @@ class Permissions extends PagesType {
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return parent::getIterator(); return parent::getIterator();
} }

View File

@@ -801,6 +801,7 @@ class Session extends Wire implements \IteratorAggregate {
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
$data = $this->sessionInit ? $_SESSION[$this->sessionKey] : $this->data; $data = $this->sessionInit ? $_SESSION[$this->sessionKey] : $this->data;
return new \ArrayObject($data); return new \ArrayObject($data);
@@ -1291,9 +1292,14 @@ class Session extends Wire implements \IteratorAggregate {
* ~~~~~ * ~~~~~
* *
* @param string $url URL to redirect to * @param string $url URL to redirect to
* @param bool|int $status Specify true for 301 permanent redirect, false for 302 temporary redirect, or * @param bool|int $status One of the following (or omit for 301):
* in 3.0.166+ you can also specify the status code (integer) rather than boolean. * - `true` (bool): Permanent redirect (same as 301).
* Default is 301 (permanent). * - `false` (bool): Temporary redirect (same as 302).
* - `301` (int): Permanent redirect using GET. (3.0.166+)
* - `302` (int): “Found”, Temporary redirect using GET. (3.0.166+)
* - `303` (int): “See other”, Temporary redirect using GET. (3.0.166+)
* - `307` (int): Temporary redirect using current request method such as POST (repeat that request). (3.0.166+)
* @see Session::location()
* *
*/ */
public function ___redirect($url, $status = 301) { public function ___redirect($url, $status = 301) {
@@ -1354,17 +1360,22 @@ class Session extends Wire implements \IteratorAggregate {
} }
/** /**
* Perform a temporary (302) redirect * Perform a temporary redirect
* *
* This is an alias of `$session->redirect($url, false);` that sends only the * This is an alias of `$session->redirect($url, false);` that sends only the
* location header, which translates to a 302 redirect. * location header, which translates to a 302 redirect.
* *
* @param string $url * @param string $url
* @param int $status One of the following HTTP status codes, or omit for 302 (added 3.0.192):
* - `302` (int): “Found”, Temporary redirect using GET. (default)
* - `303` (int): “See other”, Temporary redirect using GET.
* - `307` (int): Temporary redirect using current request method such as POST (repeat that request).
* @since 3.0.166 * @since 3.0.166
* @see Session::redirect()
* *
*/ */
public function location($url) { public function location($url, $status = 302) {
$this->redirect($url, false); $this->redirect($url, $status);
} }
/** /**

View File

@@ -1401,6 +1401,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
// check for items that resolve to blank // check for items that resolve to blank
if(is_null($key) || (is_string($key) && !strlen(trim($key)))) { if(is_null($key) || (is_string($key) && !strlen(trim($key)))) {
// @todo option to allow for these to be sorted regularly
$unidentified[] = $item; $unidentified[] = $item;
continue; continue;
} }
@@ -1758,6 +1759,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return \ArrayObject|Wire[] * @return \ArrayObject|Wire[]
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->data); return new \ArrayObject($this->data);
} }
@@ -1778,6 +1780,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return int * @return int
* *
*/ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->data); return count($this->data);
} }
@@ -1793,6 +1796,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @param Wire|mixed $value Value of item. * @param Wire|mixed $value Value of item.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetSet($key, $value) { public function offsetSet($key, $value) {
$this->set($key, $value); $this->set($key, $value);
} }
@@ -1806,6 +1810,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return Wire|mixed|bool Value of item requested, or false if it doesn't exist. * @return Wire|mixed|bool Value of item requested, or false if it doesn't exist.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($key) { public function offsetGet($key) {
if($this->offsetExists($key)) { if($this->offsetExists($key)) {
return $this->data[$key]; return $this->data[$key];
@@ -1825,6 +1830,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return bool True if item existed and was unset. False if item didn't exist. * @return bool True if item existed and was unset. False if item didn't exist.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetUnset($key) { public function offsetUnset($key) {
if($this->offsetExists($key)) { if($this->offsetExists($key)) {
$this->remove($key); $this->remove($key);
@@ -1845,6 +1851,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return bool True if the item exists, false if not. * @return bool True if the item exists, false if not.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetExists($key) { public function offsetExists($key) {
return array_key_exists($key, $this->data); return array_key_exists($key, $this->data);
} }

View File

@@ -378,6 +378,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->data); return new \ArrayObject($this->data);
} }
@@ -482,6 +483,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @param int|string|array|object $value Value of item. * @param int|string|array|object $value Value of item.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetSet($key, $value) { public function offsetSet($key, $value) {
$this->set($key, $value); $this->set($key, $value);
} }
@@ -495,6 +497,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @return int|string|array|object Value of item requested, or false if it doesn't exist. * @return int|string|array|object Value of item requested, or false if it doesn't exist.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetGet($key) { public function offsetGet($key) {
$value = $this->get($key); $value = $this->get($key);
return is_null($value) ? false : $value; return is_null($value) ? false : $value;
@@ -511,6 +514,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @return bool True if item existed and was unset. False if item didn't exist. * @return bool True if item existed and was unset. False if item didn't exist.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetUnset($key) { public function offsetUnset($key) {
if($this->__isset($key)) { if($this->__isset($key)) {
$this->remove($key); $this->remove($key);
@@ -520,7 +524,6 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
} }
} }
/** /**
* Determines if the given index exists in this WireData. * Determines if the given index exists in this WireData.
* *
@@ -532,6 +535,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @return bool True if the item exists, false if not. * @return bool True if the item exists, false if not.
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetExists($key) { public function offsetExists($key) {
return $this->__isset($key); return $this->__isset($key);
} }

View File

@@ -253,6 +253,7 @@ class WireDataDB extends WireData implements \Countable {
* @return int * @return int
* *
*/ */
#[\ReturnTypeWillChange]
public function count() { public function count() {
$table = $this->table(); $table = $this->table();
$sql = "SELECT COUNT(*) FROM `$table` WHERE source_id=:source_id"; $sql = "SELECT COUNT(*) FROM `$table` WHERE source_id=:source_id";
@@ -355,6 +356,7 @@ class WireDataDB extends WireData implements \Countable {
return true; return true;
} }
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->getArray()); return new \ArrayObject($this->getArray());
} }

View File

@@ -1551,6 +1551,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
* *
*/ */
public function closeConnection() { public function closeConnection() {
$this->pdoLast = null;
$this->reader['pdo'] = null; $this->reader['pdo'] = null;
$this->writer['pdo'] = null; $this->writer['pdo'] = null;
$this->reader['init'] = false; $this->reader['init'] = false;

View File

@@ -123,6 +123,7 @@ class WireDatabasePDOStatement extends \PDOStatement {
* @return bool * @return bool
* *
*/ */
#[\ReturnTypeWillChange]
public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR) { public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR) {
$result = parent::bindValue($parameter, $value, $data_type); $result = parent::bindValue($parameter, $value, $data_type);
if($this->debugMode && strpos($parameter, ':') === 0) { if($this->debugMode && strpos($parameter, ':') === 0) {
@@ -141,6 +142,7 @@ class WireDatabasePDOStatement extends \PDOStatement {
* @throws \PDOException * @throws \PDOException
* *
*/ */
#[\ReturnTypeWillChange]
public function execute($input_parameters = NULL) { public function execute($input_parameters = NULL) {
if($this->debugMode) { if($this->debugMode) {
return $this->executeDebug($input_parameters); return $this->executeDebug($input_parameters);

View File

@@ -415,6 +415,7 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
return $value; return $value;
} }
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
if($this->lazy) { if($this->lazy) {
$data = $this->getArray(); $data = $this->getArray();
@@ -424,23 +425,28 @@ class WireInputData extends Wire implements \ArrayAccess, \IteratorAggregate, \C
} }
} }
#[\ReturnTypeWillChange]
public function offsetExists($key) { public function offsetExists($key) {
return isset($this->data[$key]); return isset($this->data[$key]);
} }
#[\ReturnTypeWillChange]
public function offsetGet($key) { public function offsetGet($key) {
return $this->__get($key); return $this->__get($key);
} }
#[\ReturnTypeWillChange]
public function offsetSet($key, $value) { public function offsetSet($key, $value) {
$this->__set($key, $value); $this->__set($key, $value);
} }
#[\ReturnTypeWillChange]
public function offsetUnset($key) { public function offsetUnset($key) {
unset($this->data[$key]); unset($this->data[$key]);
if($this->lazy && isset($this->unlazyKeys[$key])) unset($this->unlazyKeys[$key]); if($this->lazy && isset($this->unlazyKeys[$key])) unset($this->unlazyKeys[$key]);
} }
#[\ReturnTypeWillChange]
public function count() { public function count() {
return count($this->data); return count($this->data);
} }

View File

@@ -445,6 +445,7 @@ class WireInputDataCookie extends WireInputData {
* @param mixed $key * @param mixed $key
* *
*/ */
#[\ReturnTypeWillChange]
public function offsetUnset($key) { public function offsetUnset($key) {
if(!$this->allowSetCookie($key)) return; if(!$this->allowSetCookie($key)) return;
parent::offsetUnset($key); parent::offsetUnset($key);

View File

@@ -386,6 +386,7 @@ abstract class WireSaveableItems extends Wire implements \IteratorAggregate {
return $this->getAll()->find($selectors); return $this->getAll()->find($selectors);
} }
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return $this->getAll(); return $this->getAll();
} }

View File

@@ -251,6 +251,7 @@ class Languages extends PagesType {
* @return PageArray * @return PageArray
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
if($this->languages && count($this->languages)) return $this->languages; if($this->languages && count($this->languages)) return $this->languages;
$languages = $this->wire('pages')->newPageArray(); $languages = $this->wire('pages')->newPageArray();

View File

@@ -387,6 +387,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
* @return \ArrayObject * @return \ArrayObject
* *
*/ */
#[\ReturnTypeWillChange]
public function getIterator() { public function getIterator() {
return new \ArrayObject($this->data); return new \ArrayObject($this->data);
} }

View File

@@ -243,6 +243,7 @@ class PagerNav implements \IteratorAggregate {
return $this->pager; return $this->pager;
} }
#[\ReturnTypeWillChange]
public function getIterator() { return new \ArrayObject($this->getPager()); } public function getIterator() { return new \ArrayObject($this->getPager()); }
public function getFirstItem() { return $this->firstItem; } public function getFirstItem() { return $this->firstItem; }
public function getItemsPerPage() { return $this->itemsPerPage; } public function getItemsPerPage() { return $this->itemsPerPage; }