Needs work
Project:
PHP
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Jun 2009 at 09:09 UTC
Updated:
7 Nov 2015 at 13:56 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
EvanDonovan commentedWhat would be the advantage of this over the current php_eval() in Drupal 7?
New features would be added to 7.x, so I'm changing the version number.
Comment #2
liquixis commentedI didn't know about php_eval(), because there is not any link to it on http://api.drupal.org/api/function/drupal_eval/6
This one will return result and output separately. So we could get result and treat output if it exists as an error message.
drupal_eval() initially and php_eval() now was developed afaik for theming, this version has no such specificity and usefull for any cases.
Code passed as is, without need to surround it with
.In my version there are no manipulations with $theme_path, so may be it needs to be added.
Also, if code in php_eval() will use (set) variable with name "old_theme_path", php_eval() will not work properly.
So, I think we need rename php_eval() to something associated with theming and add new drupal_eval() separately.
Comment #3
chx commentedhttp://api.drupal.org/api/function/php_eval/7 we develop for Drupal 7 so see this. All PHP related functionality goes in PHP module. Check http://drupal.org/node/320 on how to check out HEAD.
Comment #4
liquixis commentedI have found http://api.drupal.org/api/function/php_eval/7 already.
Thanks, but I already know how to check out (I use Eclipse). But I don't understand why I have to use check out for this case, to make a patch?
Comment #5
chx commentedYes. Your original patch was against Drupal 6 but features go into Drupal 7. Also it was in common.inc and now it needs to be in php module
Comment #6
sivaji_ganesh_jojodae commentedattached is a patch which tries to merge the previous patch and
php_evalin php.module.Comment #7
sivaji_ganesh_jojodae commentedComment #9
danielb commented+1 for the idea of passing $variables to make available to the user
several of my modules already use a custom version of drupal_eval() because it was basically useless for a lot of cases if you had no data available to work with.
Anyone know what went wrong in the test? Was it the changed return value?
Comment #10
sunRe-rolled against HEAD.
+ added a couple of tests, including simple variable scope security test.
Comment #12
sunEven better. Even more useful. Even more secure.
Comment #13
sunYay, tests pass! :)
With fields + stuff in core, this patch becomes a bit more important.
Comment #14
danielb commentedGreat, thanks for taking an interest here sun. I should mention it would be convenient if the php filter format could be given vars, and the filter_form() could explain available variables to the user. Haven't given that much thought though.
Comment #15
sun@danielb: Please forget about passing variables to the PHP code filter. The filter system, as of now, does not support any kind of context.
This patch is about php_eval(), not about the PHP filter. I know of a couple of contributed modules that could not use php_eval() before, because the evaluated PHP code needed access to variables in the context, such as $node.
In terms of Drupal core, this facility would be very helpful for Block page visibility settings, where you can enter PHP code in case the PHP module is enabled.
Comment #16
chx commentedWhy not make the default array() and spare the isset? array $foo = NULL is weird, I say.
Comment #17
danielb commented@sun, I know the filter system doesn't support this now, but it absolutely should. Using filter formats is an ideal and consistent way to allow php input, and making the variables available there is just as important as making them available in a custom php textarea. Giving users the ability to use variables is the central vibe of this issue, and that will have to be the next step. A further benefit is that we need a consistent standard help interface for explaining to the user what variables are available for them to use, similar to the tokens fieldset.
Comment #18
cdale commentedWould it be worth while changing the function to something like this so that it can also be used for modules like CCK where they want to get an actual PHP variable back, and not HTML. I've been using the following on some of my custom projects for some time now.
Basically, the $drupal_eval flag modifies whether we get back php values, or a string of output. Of course, any errors that occur when returning PHP values will be silently lost. Whether this is good or bad is up for someone else to decide.
Comment #19
MichaelCole commented#12: drupal.php-eval.12.patch queued for re-testing.
Comment #20
ff1 commentedBumping to D8...
Comment #21
kscheirer#12: drupal.php-eval.12.patch queued for re-testing.
Comment #23
swentel commentedComment #24
hass commentedThis requires an update as some things have changed in tests.