Greetings,

I have the problem when trying to read PHP snippet (with PHP tags) from variable table. I have a textarea setting where user should enter PHP snippet with PHP tags (because drupal_eval() function requires them). This settings is saved and cached correctly:
1. There is a row in variable table with my setting (name: ld_condition_snippet, value: s:21:" return TRUE; ";
2. There is the following string in cache table, 'variables' cid (s:20:"ld_condition_snippet";s:21:" return TRUE; ";)

When I execute variable_get('ld_condition_snippet', '') I receive an empty string instead of my PHP snippet.

I put print_r($variable); in the variable_init() function right after this code:

  else {
    $result = db_query('SELECT * FROM {variable}');
    while ($variable = db_fetch_object($result)) {

and here is what I've got: stdClass Object ( [name] => ld_condition_snippet [value] => s:21:""; )

The problem disappeared when I removed PHP tags and saved the snippet without them. May be this is a problem of PHP5 configuration?

P.S. I looked at block.module to find how it was implemented there and found that you do the same:
1. db_query('SELECT ...')
2. db_fetch_object($result)
3. drupal_eval($block->pages).
It is assumed that PHP tags should be saved in the block table as well. I output $block->pages value onto the screen and it was truncated in the beginning, nevertheless block visibility snippet is working correctly which is rather strange for me.

Comments

tr’s picture

Category: bug » support
Status: Active » Closed (won't fix)

I think your problem with not seeing the php is the same as your problem with the above post: You didn't escape your tags, so the browser is interpreting them. If you want to see the contents of the variable you can't just print_r(), you have to wrap the output in <pre></pre> in order to keep the browser from interpreting the tags.

Drupal 5 is no longer supported. If you have a similar support request for Drupal 6 or higher please open a new issue.