【发布时间】:2015-04-24 19:02:02
【问题描述】:
我需要一些帮助,我有 2 个 php 文件,当我调用一些函数时它告诉我
致命错误:在第 13 行调用 /home/f77inq/public_html/php/shares.php 中未定义的函数 get_contents()
即使在我调用我输入的函数的文件中 require("name ofmy file");
shares.php
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Shares</title>
<link rel='stylesheet' type='text/css' href='style.css' />
</head>
<body>
adad
<?php
$data = get_contents();
print_contents($data);
?>
</body>
</html>
这是我从中调用函数的文件。
<?php
require("../../php_include/services.php");
require("../../php_include/query.php");
putenv("ORACLE_HOME=/oracle/product/12.1.0/dbhome_1");
function get_contents() {
$conn = db_connect();
$shares = get_share($conn);
db_disconnect($conn);
$contents = array('shares' => $shares);
return $contents;
}
function print_contents($contents) {
?>
<table>
<tr>
<th>Company Name</th>
<th>Rate</th>
</tr>
<?php
foreach ($contents['shares'] as $share) {
print "<tr>";
//****** LINKS TO EVERY
$identifier = urlencode($share['COMPANY']);
print "<td><a href='share-details.php?company={$identifier}'>{$share['COMPANY']}</a></td>";
print "<td>{$share['RATE']}</td>";
print "</tr>";
}
?>
</table>
<?php
}
require ("shares.php"); //<<<<<<<<<<<<<<<<<<<<<<
?>
正如您在下面看到的,我需要共享 php 文件。
两个文件位于同一个文件夹中
【问题讨论】:
-
您是否在 share.php 文件中包含了 php 文件??
-
这似乎倒退了。通常你把函数放在你用
require加载的脚本中调用函数的脚本中。 -
@habibulhaq 他这样做是相反的:定义函数的脚本包括
share.php。转到第二个脚本的末尾。 -
@KhairulIslam 这没有意义。
-
@Nico12345,您这里的代码绝对有效并且工作正常。还有一些你不知道的事情发生了,在文件顶部运行
debug_print_backtrace()并查看它的加载位置。
标签: php file require classnotfound