Answer the question
In order to leave comments, you need to log in
include and return construct?
Example 5. include() and return()
statement return.php
$var = 'PHP';
return $var;
noreturn.php
$var = 'PHP';
testreturns.php
$foo = include 'return.php';
echo $foo; // prints 'PHP'
$bar = include 'noreturn.php';
echo $bar; // prints 1
but there is no function for it to work return?why prints php
Answer the question
In order to leave comments, you need to log in
Maybe it will be clearer this way:
File foo.php
$foo = "foo-php";
return $foo;
$x = include("foo.php"); // $x хранит "foo-php", т.к. использовался return
$y = include("bar.php"); // $y хранит 1, т.к. нет return, соответственно функция include вернула 1
Return Value Handling: The include statement returns FALSE on error and issues a warning. Successful includes, unless overridden in the include file, return a value of 1. It is possible to issue a return statement within an include file to end the execution process in that file and return to executing the include file. It is also possible to return a value from include files. You can get the include value as if you were calling a normal function. Although this is not possible when including a remote file, only if the output of the remote file does not contain the correct PHP start and end tags (just like the local file). You can define the required variables inside these tags and they will be present in the place where the file was included.php.net/manual/en/function.include.php
Because include is a special language construct, parentheses are not required to enclose an argument. Be careful when comparing the return value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question