2010-08-18 67 views
0

可以说,我通过PHP如何调用包含文件的功能

include "Services.php"; 
使文件 Services.php

<?php 

$myGlobalVar='ranSTR'; 

function serv1($num) 
{ 
    //some processing... 
    return $num; 
} 

function serv2($num) 
{ 
    //some processing... 
    return $num; 
} 

?> 

,我包括在其他一些文件可以说myFile.php

require "Services.php"; 
  • 我如何可以调用它的功能myFile.php

回答

20

你可以调用这些函数中的任何一个。包含文件后,这些函数将被放置在全局范围内。

你有没有尝试过:

include "Services.php"; 

$num = 123; 

serv1($num); 

从DOC:

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

退房有关详细信息,这两个文档资源在您无法理解什么:

+0

我试过,但我不断收到致命错误:调用未定义的函数 – 2016-06-18 08:23:32

+0

对不起,我发现我需要像这样的页面的问题:需要(“HTTP://本地主机/路径/到/required/file.php“); – 2016-06-18 08:28:41

3

就打电话给他们相同的,就像任何其他功能:

serv1(42); 
3

你应该只能够调用serv2(3)或任何需要是。