Skip to content

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

@KlausIllmayer

Description

@KlausIllmayer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Proposed Skosmos 3.x issues

    Status

    NatLibFi priority Medium

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions