Skip to content

Add extra php attribute to methods for 8+ Fixes #52#53

Merged
szepeviktor merged 4 commits into
php-stubs:masterfrom
janw-me:master
Sep 30, 2022
Merged

Add extra php attribute to methods for 8+ Fixes #52#53
szepeviktor merged 4 commits into
php-stubs:masterfrom
janw-me:master

Conversation

@janw-me
Copy link
Copy Markdown
Contributor

@janw-me janw-me commented Sep 30, 2022

These functions are giving notices on php 8+.
The fix is adding a extra php attribute to the methods: #[ReturnTypeWillChange]

There where a couple of difficulties. So I took a different approach.

  1. Just using sed for a method couldn't target the function of a specific class. So I used php reflection.
  2. I wanted to prevent adding multiple #[ReturnTypeWillChange] So I check if it's not already present.
    So when PHP 8.1: fix deprecation warnings WordPress/Requests#505 lands, this won't create duplicates.
  3. I wanted to make sure the indenting was correct for the attribute.

Overall fun thing to include.

These functions are giving notices on php 8+.
The fix is adding a extra php attribute to the methods: #[ReturnTypeWillChange]
@szepeviktor
Copy link
Copy Markdown
Member

Overall fun thing to include.

:)
Thank you!!

@szepeviktor
Copy link
Copy Markdown
Member

I'm very-very happy for your PR.

What do you think about my commits?

@janw-me
Copy link
Copy Markdown
Contributor Author

janw-me commented Sep 30, 2022

The changes all seem fine by me.
Seeing the speed you made these. It's obvious you are far more comfortable with these type of commands.

One small note, that doesn't need to be changed.
Reason I used [[:space:]] is (posix) compatibility.
I understand that is not a problem here.

@szepeviktor
Copy link
Copy Markdown
Member

All right. I agree.

But Bash is "improved POSIX" :)

@szepeviktor szepeviktor merged commit a1dfa9f into php-stubs:master Sep 30, 2022
@szepeviktor
Copy link
Copy Markdown
Member

While releasing v6.0.2

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to class@anonymous::getInheritedTagsForParam() must be an instance of phpDocumentor\Reflection\DocBlock\Tags\Param, instance of phpDocumentor\Reflection\DocBlock\Tags\InvalidTag given, called in /home/viktor/src/php-stubs/wordpress-stubs/visitor.php on line 509 and defined in /home/viktor/src/php-stubs/wordpress-stubs/visitor.php:535
Stack trace:
#0 /home/viktor/src/php-stubs/wordpress-stubs/visitor.php(509): class@anonymous->getInheritedTagsForParam()
#1 /home/viktor/src/php-stubs/wordpress-stubs/visitor.php(467): class@anonymous->discoverInheritedArgs()
#2 /home/viktor/src/php-stubs/wordpress-stubs/visitor.php(360): class@anonymous->addTags()
#3 /home/viktor/src/php-stubs/wordpress-stubs/visitor.php(340): class@anonymous->postProcessNode()
#4 /home/viktor/src/php-stubs/wordpress-stubs/visitor.php(330): class@anonymous->postProcessNode()
#5 /home/viktor/src/php-stubs/wordpress-stubs/vendor/php-stubs/generator/src/Result.php(49): class@anonymous->getStubStmts()
#6 /home/v in /home/viktor/src/php-stubs/wordpress-stubs/visitor.php on line 535

Viktor must work!

@szepeviktor
Copy link
Copy Markdown
Member

This error does not belong here.

Comment thread generate.sh
for METHOD in "${REQUESTS_V1_METHODS[@]}"; do
# Get the line number where the method is defined.
LINE="$(php -r "require 'wordpress-stubs.php'; print (new ReflectionMethod('${METHOD}'))->getStartLine();")"
echo "${METHOD} is defined on line ${LINE}."
Copy link
Copy Markdown
Member

@szepeviktor szepeviktor Sep 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@janw-me I've added a check here. Some methods do not exist in earlier core releases.

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.

2 participants