Monthly Archives: August 2013

Nowdoc and heredoc in PHP

From the manual:

Nowdocs are to single-quoted strings what heredocs are to double-quoted strings. A nowdoc is specified similarly to a heredoc, but no parsing is done inside a nowdoc. The construct is ideal for embedding PHP code or other large blocks of text without the need for escaping.

Look that the difference between those 2 is that nowdocs uses single quotes when defining the tag (that can be anything you want) and heredocs doesn’t.

$foo = 'bar';

$now = <<<'NOW'
    I'm now, $foo!
NOW;

$here = <<<HERE
    I'm here, $foo!
HERE;

In this case:

$now is "I'm now, $foo!"

$here is "I'm here, bar!"

Ref: http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
http://stackoverflow.com/a/11153164

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