在定义函数之前调用它|的PHP [英] Calling a function before it's defined | PHP

查看:85
本文介绍了在定义函数之前调用它|的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个文件中,是否有任何可能的方式-请注意,只有一个文件.在尚未定义的函数(例如

Is there any possible way when in one file - please note, just one file. To call a function when it isn't defined yet, e.g.

<?php

echo global_title();

function global_title()
{
    $title = $_GET['name'];

    return $title;
}

?>

我不知道该怎么解释,但这不太可能吗?另一个文件(不包含它)中的变量呢?可以在另一个文件中调用,例如

I don't know how to explain this, but it's not quite possible isn't it? What about variable from another file (without including it) can be called in a different file, e.g.

config.php

<?php

$db = "localhost";

?> 

index.php

<?php

// I do not want it to be accessed by including it or using sessions

echo $db;

?>

知道我的意思吗? :)

Know what I mean? :)

推荐答案

您可以调用在调用后定义的函数.那是因为PHP首先解析文件,然后执行它.

You can call a function which is defined after calling it. That's because PHP first parses the file and then executes it.

对于变量-这是不可能的,您必须包含文件.

As for the variable - this is not possible, you have to include the file.

这篇关于在定义函数之前调用它|的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆