diff --git a/phpQuery/phpQuery.php b/phpQuery/phpQuery.php index 118c94b..0788f7a 100644 --- a/phpQuery/phpQuery.php +++ b/phpQuery/phpQuery.php @@ -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) diff --git a/phpQuery/phpQuery/DOMDocumentWrapper.php b/phpQuery/phpQuery/DOMDocumentWrapper.php index aae5ee0..7ddd485 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) { @@ -441,7 +443,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 { @@ -510,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 diff --git a/phpQuery/phpQuery/phpQueryObject.php b/phpQuery/phpQuery/phpQueryObject.php index be31e65..f097eac 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()); @@ -1672,9 +1672,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(); } @@ -2989,6 +2991,7 @@ public function removeData($key) { /** * @access private */ + #[\ReturnTypeWillChange] public function rewind(){ $this->debug('iterating foreach'); // phpQuery::selectDocument($this->getDocumentID()); @@ -3004,12 +3007,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; } @@ -3024,7 +3029,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 ] ) @@ -3041,6 +3047,7 @@ public function next($cssSelector = null){ /** * @access private */ + #[\ReturnTypeWillChange] public function valid(){ return $this->valid; } @@ -3049,18 +3056,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); @@ -3068,6 +3078,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.");