Ne yerine eval () kullanabilir miyim?

0 Cevap php

Örneğin ben, bir sonuç üretmek için idam edilmesi gereken bazı değişkenleri içeren bir dize var:

define('RUN_THIS', '\$something.",".$somethingElse');

Ve eval()-değerlendirmeler yapılmıştır edilir:

$foo = eval("return ".RUN_THIS.";");

Ben değerlendirilen alır dize kullanıcı girişi ise eval güvensiz olduğunu anlıyoruz. Örneğin ben her şeyi eval desteklemiyor Facebook'un HipHop kaçmak istedim, ancak () bunu yapamadı.

Bu etkili bir şekilde aynı sonucu eval() - Görünüşe göre ben call_user_func() kullanabilir? Gerçekten de böyle ise, eval(), olmadığında güvenli olduğu kabul edilir nasıl?

Edit: In response to the comments, I didn't originally make it clear what the goal is. The constant is defined in advance in order that later code, be it inside a class that has access to the configuration constants, or procedural code, can use it in order to evaluate the given string of variables. The variables that need to be evaluated can vary (completely different names, order, formatting) depending on the situation but it's run for the same purpose in the same way, which is why I currently have the string of variables set in a constant in this way. Technically, eval() is not unsafe as long as the config.php that defines the constants is controlled but that wasn't the point of the question.

0 Cevap