From 29977ce2159dee1e3ce801949741dd23cd60c814 Mon Sep 17 00:00:00 2001 From: sfinktah Date: Sat, 12 Aug 2023 09:37:05 +1000 Subject: [PATCH 1/2] hacks to quiet php8.1 warnings --- phpQuery/phpQuery.php | 8 ++--- phpQuery/phpQuery/DOMDocumentWrapper.php | 14 ++++---- phpQuery/phpQuery/phpQueryObject.php | 41 +++++++++++++++--------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/phpQuery/phpQuery.php b/phpQuery/phpQuery.php index 08f22fc..0b43c0b 100644 --- a/phpQuery/phpQuery.php +++ b/phpQuery/phpQuery.php @@ -32,8 +32,8 @@ */ abstract class phpQuery { /** - * XXX: Workaround for mbstring problems - * + * XXX: Workaround for mbstring problems + * * @var bool */ public static $mbstringSupport = true; @@ -647,7 +647,7 @@ public static function DOMNodeListToArray($DOMNodeList) { * @todo still used ? */ public static function isMarkup($input) { - return ! is_array($input) && substr(trim($input), 0, 1) == '<'; + return ! is_array($input) && substr(trim($input ?? ''), 0, 1) == '<'; } public static function debug($text) { if (self::$debug) @@ -1341,4 +1341,4 @@ function pq($arg1, $context = null) { phpQuery::$plugins = new phpQueryPlugins(); // include bootstrap file (personal library config) if (file_exists(dirname(__FILE__).'/phpQuery/bootstrap.php')) - require_once dirname(__FILE__).'/phpQuery/bootstrap.php'; \ No newline at end of file + require_once dirname(__FILE__).'/phpQuery/bootstrap.php'; diff --git a/phpQuery/phpQuery/DOMDocumentWrapper.php b/phpQuery/phpQuery/DOMDocumentWrapper.php index a58b1f3..6de83ad 100644 --- a/phpQuery/phpQuery/DOMDocumentWrapper.php +++ b/phpQuery/phpQuery/DOMDocumentWrapper.php @@ -44,15 +44,17 @@ class DOMDocumentWrapper { public $isXHTML = false; public $isHTML = false; public $charset; - public function __construct($markup = null, $contentType = null, $newDocumentID = null) { + public function __construct($markup = null, $contentType = '', $newDocumentID = null) { if (isset($markup)) $this->load($markup, $contentType, $newDocumentID); $this->id = $newDocumentID ? $newDocumentID : md5(microtime()); } - public function load($markup, $contentType = null, $newDocumentID = null) { + public function load($markup, $contentType = '', $newDocumentID = null) { // phpQuery::$documents[$id] = $this; + if ($contentType === null) + $contentType = ''; $this->contentType = strtolower($contentType); if ($markup instanceof DOMDOCUMENT) { $this->document = $markup; @@ -131,7 +133,7 @@ protected function documentCreate($charset, $version = '1.0') { $this->document->formatOutput = true; $this->document->preserveWhiteSpace = true; } - protected function loadMarkupHTML($markup, $requestedCharset = null) { + protected function loadMarkupHTML($markup, $requestedCharset = '') { if (phpQuery::$debug) phpQuery::debug('Full markup load (HTML): '.substr($markup, 0, 250)); $this->loadMarkupReset(); @@ -153,11 +155,11 @@ protected function loadMarkupHTML($markup, $requestedCharset = null) { // @see http://www.w3.org/International/O-HTTP-charset if (! $documentCharset) { $documentCharset = 'ISO-8859-1'; - $addDocumentCharset = true; + $addDocumentCharset = true; } // Should be careful here, still need 'magic encoding detection' since lots of pages have other 'default encoding' // Worse, some pages can have mixed encodings... we'll try not to worry about that - $requestedCharset = strtoupper($requestedCharset); + $requestedCharset = $requestedCharset ? strtoupper($requestedCharset) : ''; $documentCharset = strtoupper($documentCharset); phpQuery::debug("DOC: $documentCharset REQ: $requestedCharset"); if ($requestedCharset && $documentCharset && $requestedCharset !== $documentCharset) { @@ -443,7 +445,7 @@ public function import($source, $sourceCharset = null) { // if ($fake === false) // throw new Exception("Error loading documentFragment markup"); // else -// $return = array_merge($return, +// $return = array_merge($return, // $this->import($fake->root->childNodes) // ); // } else { diff --git a/phpQuery/phpQuery/phpQueryObject.php b/phpQuery/phpQuery/phpQueryObject.php index f0dfa1d..4c4f69b 100644 --- a/phpQuery/phpQuery/phpQueryObject.php +++ b/phpQuery/phpQuery/phpQueryObject.php @@ -313,7 +313,7 @@ protected function parseSelector($query) { // TODO include this inside parsing ? $query = trim( preg_replace('@\s+@', ' ', - preg_replace('@\s*(>|\\+|~)\s*@', '\\1', $query) + preg_replace('@\s*(>|\\+|~)\s*@', '\\1', $query ?? '') ) ); $queries = array(array()); @@ -1037,7 +1037,7 @@ protected function pseudoClasses($class) { if (! $param) break; // nth-child(n+b) to nth-child(1n+b) - if ($param{0} == 'n') + if ($param[0] == 'n') $param = '1'.$param; // :nth-child(index/even/odd/equation) if ($param == 'even' || $param == 'odd') @@ -1052,17 +1052,17 @@ protected function pseudoClasses($class) { return null;'), new CallbackParam(), $param ); - else if (mb_strlen($param) > 1 && $param{1} == 'n') + else if (mb_strlen($param) > 1 && $param[1] == 'n') // an+b $mapped = $this->map( create_function('$node, $param', '$prevs = pq($node)->prevAll()->size(); $index = 1+$prevs; $b = mb_strlen($param) > 3 - ? $param{3} + ? $param[3] : 0; - $a = $param{0}; - if ($b && $param{2} == "-") + $a = $param[0]; + if ($b && $param[2] == "-") $b = -$b; if ($a > 0) { return ($index-$b)%$a == 0 @@ -1663,9 +1663,11 @@ public function size() { * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery * @deprecated Use length as attribute */ + #[\ReturnTypeWillChange] public function length() { return $this->size(); } + #[\ReturnTypeWillChange] public function count() { return $this->size(); } @@ -1878,7 +1880,7 @@ public function php($code = null) { } /** * Enter description here... - * + * * @param $code * @return unknown_type */ @@ -1889,7 +1891,7 @@ public function markupPHP($code = null) { } /** * Enter description here... - * + * * @param $code * @return unknown_type */ @@ -2264,7 +2266,7 @@ public function text($text = null, $callback1 = null, $callback2 = null, $callba } return $return; } - + /** * @return The text content of each matching element, like * text() but returns an array with one entry per matched element. @@ -2277,7 +2279,7 @@ public function texts($attr = null) { } return $results; } - + /** * Enter description here... * @@ -2645,7 +2647,7 @@ public function attr($attr = null, $value = null) { return is_null($value) ? '' : $this; } - + /** * @return The same attribute of each matching element, like * attr() but returns an array with one entry per matched element. @@ -2949,7 +2951,7 @@ public function map($callback, $param1 = null, $param2 = null, $param3 = null) { } /** * Enter description here... - * + * * @param $key * @param $value */ @@ -2966,7 +2968,7 @@ public function data($key, $value = null) { } /** * Enter description here... - * + * * @param $key */ public function removeData($key) { @@ -2980,6 +2982,7 @@ public function removeData($key) { /** * @access private */ + #[\ReturnTypeWillChange] public function rewind(){ $this->debug('iterating foreach'); // phpQuery::selectDocument($this->getDocumentID()); @@ -2995,12 +2998,14 @@ public function rewind(){ /** * @access private */ - public function current(){ + #[\ReturnTypeWillChange] + public function current() { return $this->elementsInterator[ $this->current ]; } /** * @access private */ + #[\ReturnTypeWillChange] public function key(){ return $this->current; } @@ -3015,7 +3020,8 @@ public function key(){ * @see phpQueryObject::_next() * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery */ - public function next($cssSelector = null){ + #[\ReturnTypeWillChange] + public function next($cssSelector = null) { // if ($cssSelector || $this->valid) // return $this->_next($cssSelector); $this->valid = isset( $this->elementsInterator[ $this->current+1 ] ) @@ -3032,6 +3038,7 @@ public function next($cssSelector = null){ /** * @access private */ + #[\ReturnTypeWillChange] public function valid(){ return $this->valid; } @@ -3040,18 +3047,21 @@ public function valid(){ /** * @access private */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { return $this->find($offset)->size() > 0; } /** * @access private */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->find($offset); } /** * @access private */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { // $this->find($offset)->replaceWith($value); $this->find($offset)->html($value); @@ -3059,6 +3069,7 @@ public function offsetSet($offset, $value) { /** * @access private */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { // empty throw new Exception("Can't do unset, use array interface only for calling queries and replacing HTML."); From 4188e3d46d456cc23e5c1289ebe18b6e06517a7f Mon Sep 17 00:00:00 2001 From: sfinktah Date: Mon, 14 Aug 2023 09:58:06 +1000 Subject: [PATCH 2/2] missed another null --- phpQuery/phpQuery/DOMDocumentWrapper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpQuery/phpQuery/DOMDocumentWrapper.php b/phpQuery/phpQuery/DOMDocumentWrapper.php index f7c57c8..7ddd485 100644 --- a/phpQuery/phpQuery/DOMDocumentWrapper.php +++ b/phpQuery/phpQuery/DOMDocumentWrapper.php @@ -512,7 +512,7 @@ protected function documentFragmentCreate($source, $charset = null) { * @param $markup * @return $document */ - private function documentFragmentLoadMarkup($fragment, $charset, $markup = null) { + private function documentFragmentLoadMarkup($fragment, $charset, $markup = '') { // TODO error handling // TODO copy doctype // tempolary turn off