Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

New strange error "Cannot call method getInputHtml() on class-string|object." #4579

Closed
williamdes opened this issue Feb 21, 2021 · 7 comments

Comments

@williamdes
Copy link

Bug report

Strange new error since .78 version

And the code checks if (method_exists($transformation_plugin, 'getInputHtml')) { so for me it can not be a class-string at this point 馃

Code snippet that reproduces the problem

https://github.com/phpmyadmin/phpmyadmin/blob/58c4f3fe16f17400436946be9a82b5811439107b/libraries/classes/InsertEdit.php#L3444

https://github.com/phpmyadmin/phpmyadmin/blob/58c4f3fe16f17400436946be9a82b5811439107b/libraries/classes/InsertEdit.php#L3459

Expected output

no errors

Actual output

$ composer run phpstan
> phpstan analyse
Note: Using configuration file phpstan.neon.dist.
 733/733 [鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔鈻撯枔] 100%

 ------ ----------------------------------------------------------- 
  Line   libraries/classes/InsertEdit.php                           
 ------ ----------------------------------------------------------- 
  3444   Cannot call method getInputHtml() on class-string|object.  
  3459   Cannot call method getScripts() on class-string|object.    
 ------ ----------------------------------------------------------- 
@mergeable
Copy link

mergeable bot commented Feb 21, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@MartinMystikJonas
Copy link
Contributor

MartinMystikJonas commented Feb 21, 2021

Well if transformation_plugin is string you cannot call methods on it by - >, but it will pass the method_exists check if that string contains name of class with given method.

@williamdes
Copy link
Author

https://github.com/phpmyadmin/phpmyadmin/blob/58c4f3fe16f17400436946be9a82b5811439107b/libraries/classes/InsertEdit.php#L3426

$transformation_plugin = new $class_name(); I think phpstan did start to be confused by that

@MartinMystikJonas
Copy link
Contributor

Hmm yes this is strange why it thinks it could be class-string in the first place.

williamdes added a commit to phpmyadmin/phpmyadmin that referenced this issue Feb 21, 2021
See: phpstan/phpstan#4579
Signed-off-by: William Desportes <williamdes@wdes.fr>
@ondrejmirtes
Copy link
Member

The main problem is that this should be object: https://phpstan.org/r/3d5411f4-9611-48af-abb5-85c24eef9cf4

The rule you're bumping into is that method_exists($mixed, 'foo') casts the first parameter to class-string|object and it's saving you from this scenario: https://3v4l.org/aQoTZ

But in your case the first argument should be object so that class-string will no longer be in play.

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@70756b0

williamdes added a commit to phpmyadmin/phpmyadmin that referenced this issue Feb 25, 2021
[ci skip]
Ref: phpstan/phpstan#4579
Signed-off-by: William Desportes <williamdes@wdes.fr>
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants