Hello,
On trunk we have
function conf_update_param($param, $value, $updateGlobal=false, $parser=null) { if ($parser != null) { $dbValue = call_user_func($parser, $value); } ...
the problem I have is that if value is an array or object, parser cannot be set to 'addslashes(serialize)'
Could we have an easier function:
function conf_update_param($param, $value, $parser=null) { $dbValue = $value; if ($value==='true') $value = true; elseif ($value==='false') $value = false; elseif (is_array($value) || is _object($value)) $dbValue = addslashes(serialize($value)); elseif ($parser != null) $dbValue = call_user_func($parser, $value); ... and always set global $conf ...
?
Obviously some changes are required if we decide to set the global once for all ... If we are to be beacward compatible, we can have for 2.7 only
function conf_update_param($param, $value, $parser=null, $updateGlobal=false)
and then just remove $updateGlobal ...
What do you think ?
Offline
$parser can be set to a Closure or the result of create_function, or even a pointer to a class method
isn't it enough ?
personnally I never use addslashes after serialize, never had issues
--
anyway i don't get why you want/need to always update $conf...
Offline
mistic100 wrote:
$parser can be set to a Closure or the result of create_function, or even a pointer to a class method
isn't it enough ?
obviously writing
conf_update_param('x', $val, true, function ($x) { return addslashes(serialize($x)); } )
is always a possibility that nobody will use...
mistic100 wrote:
personnally I never use addslashes after serialize, never had issues
is when your arary contains strings with ' or \
mistic100 wrote:
anyway i don't get why you want/need to always update $conf...
I don't but why is it there then ?
Offline
rvelices wrote:
is always a possibility that nobody will use...
why not ? it's clear that if nobody starts to make Closures useful nobody will use them (of it's fetched :) )
rvelices wrote:
is when your arary contains strings with ' or \
totally right (has issue with ContactForm recently)
rvelices wrote:
I don't but why is it there then ?
Because it's useful :)
I added it as an option, totally optional, your version make it mandatory, which will break thinks when people do
conf_update_param("key", serialize($value)); // 2.6 : $value is an array // 2.7 : $value is a string
edit: $conf['key'] is modified, not $value (I am doing Java with pointers everyday so I mess up !)
--
what I don't like in your version is that it doesn't let the choice of "encoding" (I now prefer JSON to serialize)
what about this
function conf_update_param($param, $value, $updateGlobal=false, $parser=null) { if ($parser != null) { $dbValue = call_user_func($parser, $value); } else if (is_array($value) || is_object($value)) { $dbValue = addslashes(serialize($value)); } else { $dbValue = $value; } ....
serialize only if no parser is defined
Offline
I precise that the aim of the modification was to add $updateGlobal, and $parser became a need
not the reverse
Offline
I like better your last version.
Speaking of json I believe that you also have to add slashes after encoding ( you cant just use 'json_encode' as parser if you have strings that may contain apostrophes quotes or antislashes)
Offline
yes of course
Offline