PHP5: How come an included function always echoes first if I call it?

后端 未结 1 895
终归单人心
终归单人心 2021-01-21 10:36

I\'ve got two files here:

ToBeIncludedFile.php


MainFile.php

         


        
相关标签:
1条回答
  • 2021-01-21 10:54

    The reason it echos first, is because it is called, and afterwards are the strings "concatenated" (more on that in a second):

    What you want in ToBeIncludedFile.php is return "World!";, not echo.

    Right now, this is what happens:

    • You include the file, which doesn't print anything, this is correct.
    • You do a concatenation of the string "Hello" and the return value of printOut(). That means, first that function is called:
    • printOut() executes and prints "World!", returning nothing.
    • Your main script then concatenates "Hello" with nothing and prints that.
    0 讨论(0)
提交回复
热议问题