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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integer notation code raises a TypeError on method_exists() in PHP 8.x #1381

Open
KlausIllmayer opened this issue Oct 21, 2022 · 0 comments
Open
Milestone

Comments

@KlausIllmayer
Copy link

At which URL did you encounter the problem?

Internal test instance of Skosmos, running with PHP 8.0.8 and Skosmos release version 2.16

What steps will reproduce the problem?

  1. Have Skosmos 2.16 running with PHP 8.x
  2. Have a vocabulary with a concept that has a skos:notation with an integer value, e.g. 35
  3. View the concept

What is the expected output? What do you see instead?

Seeing the detail view of the concept, instead there is a blank view. In the apache log files I get this error:

PHP Fatal error:  Uncaught TypeError: method_exists(): Argument #1 ($object_or_class) must be of type object|string, int given in /var/www/html/model/Concept.php:663

What browser did you use? (eg. Firefox, Chrome, Safari, Internet explorer)

Firefox but this is not relevant here.

How to solve the issue?

Since PHP 8.x the behaviour of method_exists() changed, now it raises a TypeError if it is not an object/string, which is not the case in PHP 7.x (see e.g. https://stackoverflow.com/questions/70584290/php-8-0-method-exists-on-non-object-causes-fatal-typeerror) - I've also compared the behaviour with our production instance running an older version of Skosmos and a PHP 7.x, where this error does not occur.

In https://github.com/NatLibFi/Skosmos/blob/v2.16-maintenance/model/Concept.php#L663 method_exists is called without checking if it is an object. In case of an integer the TypeError is raised, as it is the case with a skos:notation 35. Adding such a check with is_object() in the line 663 solves the issue in my understanding:

                $propertyValues[(is_object($label) && method_exists($label, 'getValue')) ? $label->getValue() : $label][] = $value->getType();

Hope, that this is the correct solution - if you prefer, I can also create a pull request.

@kouralex kouralex mentioned this issue Nov 3, 2022
4 tasks
@osma osma added this to the 3.0 milestone Nov 21, 2023
@osma osma mentioned this issue Nov 21, 2023
60 tasks
@joelit joelit moved this to Proposed Skosmos 3.0 issues (to do) in Skosmos 3.0 Backlog Aug 8, 2024
@osma osma changed the title Raising a TypeError on method_exists() in PHP 8.x Integer notation code raises a TypeError on method_exists() in PHP 8.x Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Proposed Skosmos 3.0 issues (to do)
Development

No branches or pull requests

2 participants