Blog

PHP: Adding variables in the current scope

by Ashish Datta

So earlier today I was working on a Facebook App and wanted to use “partials” in a similar fashion as Symfony’s partials. At this point, I realized I had no idea how Symfony placed variables into the current execution scope when you do things like

include_partial("somePartial", array("foo" => $foo, "bar" => $bar));

A bit of digging led me to the extract() function in PHP.

From the documentation, “extract — Import variables into the current symbol table from an array”.

Pretty neat.

One Response to “PHP: Adding variables in the current scope”

  1. chris Says:

    ..or within the partial:

    $sf_view->getAttribute(‘foo’);
    $sf_view->setAttribute(‘foo’,$foo);

    $sf_view->getAttributeHolder()->getAll();

Leave a Reply