create-function

what does this preg_replace_callback do in PHP? and how do I stop it leaking memory?

I've got a section of code on a b2evo PHP site that does the following: $content = preg_replace_callback( '/[\x80-\xff]/', create_function( '$j', 'return "&#".ord($j[0]).";";' ), $content); What does this section of code do? My guess is that it strips out ascii characters between 128 and 256, but I can't be sure. Also, ...

PHP's create_function() versus just using eval()

In PHP you have the create_function() function which creates a unique named lambda function like this: $myFunction = create_function('$foo', 'return $foo;'); $myFunction('bar'); //Returns bar Is this actually any better (apart from being more easy) then just doing: do{ $myFunction = 'createdFunction_'.rand(); } while(function_exist...

PHP sandbox/sanitize code passed to create_function

Hello, I am using create_function to run some user-code at server end. I am looking for any of these two: Is there a way to sanitize the code passed to it to prevent something harmful from executing? Alternately, is there a way to specify this code to be run in a sandboxed environment so that the user can't play around with anything ...

PHP, create_function or evalute it at runtime?

Hi all, i have a class with some method that depend by one parameter. What is the best way to write this method? Example: First way class Test{ var $code; function Test($type){ if($type=="A"){ $this->code=create_function(/*some args and some code*/); } else if($type=="B"){ $this->code=create_functi...

MYSQL stored function - create function (function definition) problem using FORMAT

Hi all, I keep receiving an error with the following code. I am trying to make a function that will format a field (content=0.0032) into a varchar/percent (content=0.32%). At the moment i'm just trying to get format to work, and it throws up an error "Error Code : 1064 You have an error in your SQL syntax; check the manual that corres...

create_function with default parameter values?

Ok, I'm looking into using create_function for what I need to do, and I don't see a way to define default parameter values with it. Is this possible? If so, what would be the best approach for inputting the params into the create_function function in php? Perhaps using addslashes? Well, for example, I have a function like so: functi...

How to fix MySQL CREATE FUNCTION query?

I want to add mysql function: CREATE FUNCTION `chf_get_translation`(translation_id INT, site_lang INT) RETURNS text CHARSET utf8 BEGIN DECLARE translation TEXT; SELECT title INTO translation FROM chf_translations WHERE key_id = translation_id AND lang_id = site_lang; RETURN translation; END But get error...

MySQL CREATE FUNCTION fails on a shared webserver

Hi, I have the following function. When I try to create it on a webserver, it fails with You do not have the SUPER privilege and binary logging is enabled (you might want to use the less safe log_bin_trust_function_creators variable) I never had the same problem with any other webhosting (and the exact same function), how can I fi...

How do I create user-defined sql functions using CakePHP?

Consider the example given on this page about creating user-defined functions in SQL and then using the user-defined function in the WHERE clause. mysql> CREATE FUNCTION myFunction(in_rep_id INT) -> RETURNS INT -> READS SQL DATA -> BEGIN -> DECLARE customer_count INT; -> -> SELECT COUNT(*) ...