1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-07 15:26:54 +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); }
public function makeCopy() { $this->preload(); return parent::makeCopy(); }
public function makeNew() { $this->preload(); return parent::makeNew(); }
#[\ReturnTypeWillChange]
public function getIterator() { $this->preload(); return parent::getIterator(); }
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); }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -862,7 +862,7 @@ class PageTraversal {
if($options === true || (is_array($options) && !empty($options['http']))) {
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();
}
#[\ReturnTypeWillChange]
public function getIterator() {
return $this->find();
}
@@ -58,6 +59,7 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
* @return int
*
*/
#[\ReturnTypeWillChange]
public function count($options = array()) {
if($this->variations) {
$count = $this->variations->count();
@@ -227,9 +229,26 @@ class PageimageVariations extends Wire implements \IteratorAggregate, \Countable
);
foreach($this->pageimage->extras() as $name => $extra) {
if(!$extra->exists()) continue;
$info["{$name}Url"] = $extra->url(false);
$info["{$name}Path"] = $extra->filename();
if($extra->exists()) {
$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'])) {

View File

@@ -432,7 +432,7 @@ class PagesPathFinder extends Wire {
if(empty($result['language']['name'])) $this->setResultLanguage($language);
}
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) {
$name = (string) $name;
if($this->pageNameCharset !== 'UTF8') return $name;
if(strpos($name, 'xn-') !== 0) return $name;
return $this->wire()->sanitizer->pageName($name, Sanitizer::toUTF8);

View File

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

View File

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

View File

@@ -801,6 +801,7 @@ class Session extends Wire implements \IteratorAggregate {
* @return \ArrayObject
*
*/
#[\ReturnTypeWillChange]
public function getIterator() {
$data = $this->sessionInit ? $_SESSION[$this->sessionKey] : $this->data;
return new \ArrayObject($data);
@@ -1291,9 +1292,14 @@ class Session extends Wire implements \IteratorAggregate {
* ~~~~~
*
* @param string $url URL to redirect to
* @param bool|int $status Specify true for 301 permanent redirect, false for 302 temporary redirect, or
* in 3.0.166+ you can also specify the status code (integer) rather than boolean.
* Default is 301 (permanent).
* @param bool|int $status One of the following (or omit for 301):
* - `true` (bool): Permanent redirect (same as 301).
* - `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) {
@@ -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
* location header, which translates to a 302 redirect.
*
* @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
* @see Session::redirect()
*
*/
public function location($url) {
$this->redirect($url, false);
public function location($url, $status = 302) {
$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
if(is_null($key) || (is_string($key) && !strlen(trim($key)))) {
// @todo option to allow for these to be sorted regularly
$unidentified[] = $item;
continue;
}
@@ -1758,6 +1759,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return \ArrayObject|Wire[]
*
*/
#[\ReturnTypeWillChange]
public function getIterator() {
return new \ArrayObject($this->data);
}
@@ -1778,6 +1780,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @return int
*
*/
#[\ReturnTypeWillChange]
public function count() {
return count($this->data);
}
@@ -1793,6 +1796,7 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
* @param Wire|mixed $value Value of item.
*
*/
#[\ReturnTypeWillChange]
public function offsetSet($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.
*
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) {
if($this->offsetExists($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.
*
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key) {
if($this->offsetExists($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.
*
*/
#[\ReturnTypeWillChange]
public function offsetExists($key) {
return array_key_exists($key, $this->data);
}

View File

@@ -378,6 +378,7 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
* @return \ArrayObject
*
*/
#[\ReturnTypeWillChange]
public function getIterator() {
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.
*
*/
#[\ReturnTypeWillChange]
public function offsetSet($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.
*
*/
#[\ReturnTypeWillChange]
public function offsetGet($key) {
$value = $this->get($key);
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.
*
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key) {
if($this->__isset($key)) {
$this->remove($key);
@@ -520,7 +524,6 @@ class WireData extends Wire implements \IteratorAggregate, \ArrayAccess {
}
}
/**
* 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.
*
*/
#[\ReturnTypeWillChange]
public function offsetExists($key) {
return $this->__isset($key);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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