dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

PHP 7.4: Undefined method named "getAttributes" of class "ReflectionClass" #1327

Closed jjarolim closed 1 year ago

jjarolim commented 1 year ago

Bug Report

Q A
BC Break no
Bundle version 1.21.1
Symfony version 5.4
PHP version 7.4.29

Summary

After installing VichUploaderBundle via composer, symfony throws the following error:

Attempted to call an undefined method named "getAttributes" of class "ReflectionClass" in AttributeReader.php line 20.

It seems that ReflectionClass::getAttributes was introduced in PHP 8 and is not available in PHP 7.4: https://www.php.net/manual/en/reflectionclass.getattributes.php

composer.json php requirement and platform config would be set to 7.4:

{
  "require": {
    "php": "7.4"
  },
  "config": {
    "platform": {
      "php": "7.4"
    }
  }
}

Current behavior

Project throws compile time exception

How to reproduce

Just install bundle on a fresh symfony 5.4 project on PHP 7.4.x

Expected behavior

No usage of that method on PHP < 8

garak commented 1 year ago

That's because you cannot use attributes in PHP 7.4 Use annotations instead (or XML mapping or yaml)

jjarolim commented 1 year ago

Ah OK thanks!

For the first try I just copied the package configuration from the documentation page Basic usage without questioning what

metadata:
  type: attribute

means.

Maybe some clarification in the sample would be cool:

metadata:
  type: attribute # PHP 8: Use attributes @see https://www.php.net/manual/en/language.attributes.overview.php

But nevertheless many thanks for the help!

Best regards from Salzburg,

Johannes

garak commented 1 year ago

Documentation in master is for latest release. For 1.21 you need to check docs in 1.x branch.