Weird custom function output in wordpress

I have a problem with WordPress. I am running this function:

function name($text = '', $relative = false, $icon = true) {

echo $text;
echo $relative;
echo $icon;

}

and the output of it is just “1” (one). How is it possible? Shouldn’t be 3 lines of code (3 answers)? I am using apache 2.4, php 5.4.1 and wordpress 3.4 beta 3 on windows 7.

Related posts

Leave a Reply

2 comments

  1. if you add wrapper dummies and line breaks to each echo, you’ll find why it is showing just “1”:

    function name($text = '', $relative = false, $icon = true) {
    
    echo "text:".$text.";<br>";
    echo "relative:".$relative.";<br>";
    echo "icon:".$icon.";<br>";
    
    }
    
    name();
    

    outputs :

    text:;
    relative:;
    icon:1;
    
  2. Thats correct.

    <?php
    $text='';
    $relative=false;
    $icon=true;
    
    echo $text;
    echo $relative;
    echo $icon;
    
    ?>
    

    First one is null, second one is false which is treated as 0 which is outputed as null. The last one is true, which is 1. Wich makes the output 1.

    As shown here:

    1
    

    (output of above script)