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

PHP 7 compatibility #64

Closed
asrob opened this issue Oct 15, 2016 · 14 comments
Closed

PHP 7 compatibility #64

asrob opened this issue Oct 15, 2016 · 14 comments
Milestone

Comments

@asrob
Copy link
Contributor

asrob commented Oct 15, 2016

Hi!

I tried to install warden (mondodb-32 branch) but I could not because of this error below. I use PHP 7.0 via homebrew, here is my installed packages:

php70
php70-intl
php70-mcrypt
php70-mongodb
php70-opcache

$ php --version

PHP 7.0.12 (cli) (built: Oct 14 2016 09:55:03) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12, Copyright (c) 1999-2016, by Zend Technologies

$ composer --version

Composer version 1.2.1 2016-09-12 11:27:19

Error message:

Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
PHP Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
PHP Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23

@mikeddeeson
Copy link
Contributor

Hi @asrob,

Thanks for looking at Warden. We haven't tried it on PHP 7 as yet, so I wondered if this was a PHP version issue.

I have just had a quick search for this error message and found the following issue with Mongodb-odm: alcaeus/mongo-php-adapter#58 and doctrine/DoctrineMongoDBBundle#351 which seemed related.

Are you able to try it with an older version of PHP at all to see if this changes anything?

Thanks
Mike

@asrob asrob changed the title Fatal error: Cannot use 'String' as class name as it is reserved PHP 7 compatibility Nov 30, 2016
@mikeddeeson
Copy link
Contributor

Hi @asrob,

Looking at the Mongodb driver details (https://docs.mongodb.com/ecosystem/drivers/php/), this may be an issue to do with the version of the driver that is being used.

Our composer file details to use ^1.0, but it seems that it is only from 1.1 that PHP7 is supported.

Are you able to update the mongodb package to use at least 1.1 to see if this then fixes this issue?

Thanks
Mike

@asrob
Copy link
Contributor Author

asrob commented Dec 8, 2016

Hi @mikeddeeson,

I tried it, but it didn't solve this issue. The full output is the following:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing twig/twig (v1.27.0)
  - Installing twig/twig (v1.28.2)
    Loading from cache

  - Removing doctrine/common (v2.6.1)
  - Installing doctrine/common (v2.6.2)
    Downloading: 100%

  - Removing symfony/assetic-bundle (v2.8.0)
  - Installing symfony/assetic-bundle (v2.8.1)
    Downloading: 100%

  - Removing mongodb/mongodb (1.0.3)
  - Installing mongodb/mongodb (1.1.0)
    Downloading: 100%

  - Removing doctrine/mongodb (1.3.0)
  - Installing doctrine/mongodb (1.4.0)
    Downloading: 100%

  - Removing monolog/monolog (1.21.0)
  - Installing monolog/monolog (1.22.0)
    Loading from cache

Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
PHP Fatal error:  Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception


  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:
  Fatal error: Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
  PHP Fatal error:  Cannot use 'String' as class name as it is reserved in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23

Attached a picture as well.
screen shot 2016-12-08 at 15 22 06

@royalcollectiontrust
Copy link

OK thanks @asrob - I was hoping that might have been the answer 😄 .

I'll have a look to see if I can find anything else that might cause this and will let you know

@asrob
Copy link
Contributor Author

asrob commented Dec 14, 2016

@royalcollectiontrust,

I found this line https://github.com/doctrine/mongodb-odm/blob/master/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DoctrineAnnotations.php#L42
AFAIK because of that lines above it shouldn't "import" these .php files.

@mikeddeeson
Copy link
Contributor

Is it these lines which is causing the problem in the MongoDB ODM - if you comment them out does it work?

I'm looking at the MongoDB ODB github to see if there are any issues around this as well

@mikeddeeson
Copy link
Contributor

Looking through the MongoDb ODB issue queue it does seem that that fix for not including those classes was added to cater for this issue.

Can you debug your code a bit and see if it is actually include these classes for some reason - i.e. the check for the php version is not working correctly?

@wturrell
Copy link
Contributor

wturrell commented Dec 15, 2016

This is because where you're defining your fields, in:

src/Deeson/WardenBundle/Document/DashboardDocument.php
src/Deeson/WardenBundle/Document/ModuleDocument.php
src/Deeson/WardenBundle/Document/SiteDocument.php

Rather than:

@Mongodb\String

you need:

@Mongodb\@Field(type="string")

See: doctrine/mongodb-odm#1368 (i.e. loading of String.php is triggered by the annotations, not the require_once __DIR__ . '/String.php'; in DoctrineAnnotations.php - indeed you can comment that entire conditional out and it'll still fail.)

I did also upgrade to MongoDB ORM 1.1 for the PHP7 support, as you'd already noted. Other than that composer.json is unchanged.

The install works fine after that and I'm prompted for username/password. If I can I'll submit a PR later, but I'll attempt to get Warden working first as I've not used it before...

(This is on Debian 8.6, by the way, using the DotDeb PHP 7 packages.)

@mikeddeeson
Copy link
Contributor

Hi @wturrell,

Thanks for this, that would make sense that it is the data typing on the document (I just haven't had got an environment currently to test with PHP7).

If you can get it working a pull request would be appreciated as I can test it against the PHP 5.6 as well :)

wturrell added a commit to wturrell/warden that referenced this issue Dec 15, 2016
Symptom:

Fatal error: Cannot use 'String' as class name as it is reserved
in /Users/asrob/Sites/warden/vendor/doctrine/mongodb-odm/
lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 23
when running "composer install"

This is because 'String' is a reserved word in PHP 7:
http://php.net/manual/en/reserved.other-reserved-words.php

Although there was a fix here which checked the PHP version...

doctrine/mongodb-odm#1168

... the String class is still dynamically loaded when referred
to in a Docblock annotation, like this: @string (or @Bool etc.)

Doctrine have deprecated over a dozen annotations like @string
in favour of @field, where you must specify the type like this:

    /**
     * @field(type="string")
     */

     protected $foo;

NB: 'string' is the default type anyway.

In Warden, it's @mongodb\Field... because of the 'use' statement

Official docs for @field (and other annotations):
http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html#field

Allowed field types:
http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/basic-mapping.html#doctrine-mapping-types
wturrell added a commit to wturrell/warden that referenced this issue Dec 15, 2016
This isn't necessary to fix issue teamdeeson#64, but it provides compatibility
with MongoDB drivers - see https://github.com/doctrine/mongodb-odm/releases

Note this new version requires PHP 5.6+

Documentation suggests 1.0.x branch will lose support after Dec 2016.
@asrob
Copy link
Contributor Author

asrob commented Dec 17, 2016

Hi,

I tried @wturrell's patch but it didn't work for me. I would attach a screenshot in order to you can see what happens.
screen shot 2016-12-17 at 10 20 54

I suppose it should work on Linux, but I didn't tested on that.

Here is the details about my environment:

Installed PHP 7.0.14 via homebrew + a few extensions (php70-intl, php70-mongodb, php70-opcache, php70-solr)

$ uname -a
Darwin valhalla 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64

$ php --version
PHP 7.0.14 (cli) (built: Dec 9 2016 07:34:25) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.14, Copyright (c) 1999-2016, by Zend Technologies

@wturrell
Copy link
Contributor

wturrell commented Dec 17, 2016

@asrob I tested it on Debian, but I'm also able to run composer, including the post-(install|update) steps, without error on an El Capitan Mac (i.e. 10.11.6, Darwin Kernel 15.6.0, PHP 7.0.14) - by which I mean:

  • cloning my fork into a new directory and pulling/switch to the fix/issue64/php7 branch
  • running composer update

Googling the Class __PHP_Incomplete_Class has no unserializer error seems to throw up some (but by no means all) Symfony users who've resolved it by clearing the cache; either with php console, or deleting the contents of app/cache manually.

Edit: incidentally, if you were missing any crucial packages, like the php70-mongodb extension, you'd get a warning and composer wouldn't let you continue (it checks the dependencies beforehand).

@asrob
Copy link
Contributor Author

asrob commented Dec 17, 2016

Hi @wturrell,

Yes, you're right. I could test it on a VPS. Installation was fine, I'm going to try adding some sites now.

So, +1 from me to this pull request! :)

@asrob
Copy link
Contributor Author

asrob commented Dec 17, 2016

@mikeddeeson @wturrell,

I've tested it on my local environment and works well. I just deleted app/cache directory and re-run composer install.

Thanks again!

@asrob
Copy link
Contributor Author

asrob commented Dec 22, 2016

I would propose this issue to be in beta5. :)

@mikeddeeson mikeddeeson added this to the 1.0-beta5 milestone Feb 22, 2017
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

No branches or pull requests

4 participants