Skip to content

Fixed Collection::offsetGet() signature for PHP 8.1#291

Open
davidbyoung wants to merge 1 commit intopaquettg:masterfrom
davidbyoung:290-fix
Open

Fixed Collection::offsetGet() signature for PHP 8.1#291
davidbyoung wants to merge 1 commit intopaquettg:masterfrom
davidbyoung:290-fix

Conversation

@davidbyoung
Copy link
Copy Markdown

Fixes #290

@kiwijuicer
Copy link
Copy Markdown

Merge would be appreciated

@dyaskur
Copy link
Copy Markdown

dyaskur commented Dec 31, 2021

merged :
https://github.com/1forU/php-html-parser

Since the original creator seemed to have abandoned this project and I can not install it on my project, so I created a fork and published it as a new package to allow me to install it on my project.

hope help other too

thanks.

@AkioSarkiz AkioSarkiz mentioned this pull request Feb 20, 2022
@dakur
Copy link
Copy Markdown

dakur commented Mar 31, 2022

You can also patch it with composer-patches composer plugin.

Patch file (e.g. patches/paquettg_phphtmlparser_fix_offsetget_deprecation.patch):

diff --git a/src/PHPHtmlParser/Dom/Node/Collection.php b/src/PHPHtmlParser/Dom/Node/Collection.php
index ff44725..6125b19 100644
--- a/src/PHPHtmlParser/Dom/Node/Collection.php
+++ b/src/PHPHtmlParser/Dom/Node/Collection.php
@@ -130,6 +130,7 @@ class Collection implements IteratorAggregate, ArrayAccess, Countable
      *
      * @return mixed
      */
+	#[\ReturnTypeWillChange]
     public function offsetGet($offset)
     {
         return $this->collection[$offset] ?? null;

List it in composer.json:

{
    "extra": {
        "patches": {
            "paquettg/php-html-parser": {
                "Fix deprecation notices for offsetGet() return type": "patches/paquettg_phphtmlparser_fix_offsetget_deprecation.patch"
            },
    }
}

⚠ Note that you have to have aforementioned composer-patches composer plugin installed first.

mr-chetan added a commit to devanoxltd/php-html-parser that referenced this pull request Aug 24, 2025
Added the #[ReturnTypeWillChange] attribute to the offsetGet method in Collection to ensure compatibility with future PHP versions and suppress deprecation warnings.

https: //github.com/paquettg/pull/291
https: //github.com/paquettg/issues/290
Co-Authored-By: David Young <6652430+davidbyoung@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error with method signature of Collection::offsetGet()

4 participants