note 126715 added to function.eval
| From: | greald at gmail dot com | Date: | Sun, 26 Dec 2021 09:10:08 +0000 |
| Subject: | note 126715 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217422@lists.php.net to get a copy of this message | ||
to avoid the evil eval() you may use the fact that function names, variable names, property names
and method names can be handled strings.
<?php
class Fruit
{
public $tomato = "Tomatos";
public function red() {return " are red. ";}
}
$fruit = new Fruit;
$fruitStr = "tomato";
$colorStr = "red";
echo $fruit->$fruitStr . $fruit->$colorStr();
// and procedural //////////////////////////////////////////
$lemon = "Lemons";
function yellow() {return " are yellow. ";}
$fruitStr = "$lemon";
$colorStr = "yellow";
echo $fruitStr . $colorStr();
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 217.100.185.202)
----
Manual Page -- https://php.net/manual/en/function.eval.php
Edit -- https://main.php.net/note/edit/126715
Del: integrated -- https://main.php.net/note/delete/126715/integrated
Del: useless -- https://main.php.net/note/delete/126715/useless
Del: bad code -- https://main.php.net/note/delete/126715/bad+code
Del: spam -- https://main.php.net/note/delete/126715/spam
Del: non-english -- https://main.php.net/note/delete/126715/non-english
Del: in docs -- https://main.php.net/note/delete/126715/in+docs
Del: other reasons-- https://main.php.net/note/delete/126715
Reject -- https://main.php.net/note/reject/126715
Search -- https://main.php.net/manage/user-notes.php