hi guys, is the 'eval' function able to execute more than one function that returns a value? As illustrated below, fcall2 seems to be ignored. Why?

πŸ˜•

<?php

$strFromDB = "fcall1();fcall2();";

$line = "";

eval("\$line = " . $strFromD😎;

echo $line;

function fcall1(){
return "fcall1-text";
}
function fcall2(){
return "fcall2-text";
}

?>

    fcall2() is not ignored. It has no side effects, but returns a value that is discarded, so it looks like it is ignored since it has no observable net effect.

    If you are not convinced, reason about what would be printed when you write:

    <?php
    function fcall1(){
        return "fcall1-text";
    }
    function fcall2(){
        return "fcall2-text";
    }
    
    $line = fcall1();
    fcall2();
    echo $line;
    ?>

      hey thanks laserlight, i can't believe i missed that one πŸ˜ƒ

        No worries πŸ™‚
        Remember to mark this thread as resolved (if it is) using the thread tools.

        Oh, and do remember that eval() should only be used as a last resort since it can lead to security vulnerabilities.

          "If eval's the answer, you're asking the wrong question" πŸ˜›

            Write a Reply...