Category Archives: Symfony2

Fix “Cannot redeclare class Symfony\…” in Symfony2 after upgrade

After upgrading from Symfony 2.2 to 2.3 I got this error in my application:

Fatal error: Cannot redeclare class Symfony\Component\HttpFoundation\FileBag in app/cache/prod/classes.php on line 1823

Another symptom was this error while trying to clear the cache for the prod environment:

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The parameter "kernel.http_method_override" must be defined.

The process to solve this problem was:

1.- Remove the cache folder:

rm -rf app/cache/prod

2.- Then clear the cache for the prod environment:

php app/console cache:clear --env=prod --no-debug

Ref:

Update composer and all packages installed with it

php composer.phar self-update
php composer.phar update

Symfony2 – ErrorException: Notice: serialize() [function.serialize]: “xxx” returned as member variable from __sleep() but does not exist in …

While storing an entity from Doctrine2 in the session under a Symfony2 application I got this error:

ErrorException: Notice: serialize() [function.serialize]: "entity_property" returned as member variable from __sleep() but does not exist in ...vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DataCollector/DataCollector.php line 27

This error was happening because my “entity_property” was declared as private and PHP has some issues serializing objects that subclass a class with private properties. Just changing that “entity_property” to protected (as it should always have been…) solver the error.

Ref: http://blog.geertvd.be/2011/09/25/symfony2-id-returned-as-member-variable-from-__sleep-but-does-not-exist

Install Doctrine2 with PEAR in MacPorts

Run those commands:

sudo /opt/local/bin/pear channel-discover pear.doctrine-project.org
sudo /opt/local/bin/pear channel-discover pear.symfony.com
sudo /opt/local/bin/pear install -a pear.doctrine-project.org/DoctrineORM-2.3.3
sudo /opt/local/bin/pear install pear.doctrine-project.org/DoctrineSymfonyConsole
sudo /opt/local/bin/pear install pear.doctrine-project.org/DoctrineSymfonyYaml

Then running doctrine -v should work but /opt/local/lib/php must be in the include_path of your PHP installation. I tried to include it in my /opt/local/etc/php5/php.ini file but didn’t work, so I added this line as the very first line in /opt/local/bin/doctrine.php:

set_include_path(get_include_path() . PATH_SEPARATOR . '/opt/local/lib/php');

Then everything worked fine.

Ref: http://delboy1978uk.wordpress.com/2012/06/26/installing-doctrine-2-2-2-on-mac-os-x/

Using MacPorts php from command line

Some time ago I had installed Apache+MySQL using MacPorts in Mac OS X. It was all OK as long as I used the web browser to navigate thru the web pages, but as I runned PHP via CLI to execute Symfony2 commands I started having problems. It said for example that my time zone was not set, and I knew for sure that I had configured it in the php.ini file.

$ php app/console doctrine:schema:update --force

  
[ErrorException] Warning: date_default_timezone_get(): It is not safe to rely on the system' s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those me thods and you are still getting this warning, you most likely misspelled th e timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' ins tead in /Users/enekochan/Documents/Webs/este.es/vendor/monolog/monolog/src/ Monolog/Logger.php line 199

          

Searching the web for a solution I realized that the problem was that I was running the binary php that comes with Mac OS X, and I didn’t have the timezone configured for it. You can see where the php.ini file is by running this:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)

The first solution i came up with was to use the full path for the MacPorts php binary file:

$ /opt/local/bin/php app/console doctrine:schema:update --force
$ /opt/local/bin/php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /opt/local/etc/php5
Loaded Configuration File => /opt/local/etc/php5/php.ini

A better solution consists on adding to the systems path /opt/local/bin before /usr/bin. This can be done adding this to ~/.bash_profile:

PATH=/opt/local/bin:$PATH;export PATH

Then you have to close and open a new terminal or source the newly edited ~/.bash_profile:

$ source ~/.bash_profile

Ref: Stackoverflow

  • Page 1 of 2
  • 1
  • 2
  • >