我要在1.php上怎么写才能在log.txt上$msg里输出的是person.php的结果,就是把那个('调入文件成功')改为那个person.php的结果
//1.php
<?php
function writeLog($msg){
$logFile = 'log.txt';
date_default_timezone_set('Asia/Chongqing');
$msg = date('Y-m-d H:i:s').' >>> '.$msg."\r\n";
file_put_contents($logFile,$msg,FILE_APPEND );
require_once('person.php');
}
writeLog('调入文件成功');
?>
//person.php
<?php
class Person{
public $name;
public $age;
function construct($name,$age){
$this->name = $name;
$this->age = $age;
}
function show() {
echo "my name is ".$this->name." ";
}
}
$sxd=new Person();
$sxd->name="sxd";
$sxd->age=22;
$sxd->show();
echo "age is ".$sxd->age;
?>
//1.php <?php function writeLog($msg){ $logFile = 'log.txt'; date_default_timezone_set('Asia/Chongqing'); $msg = date('Y-m-d H:i:s').' >>> '.$msg."\r\n"; file_put_contents($logFile,$msg,FILE_APPEND ); } require_once('person.php'); $sxd=new Person('sxd',22); $msg = $sxd->show(); writeLog($msg); ?> //person.php <?php class Person{ public $name; public $age; function __construct($name,$age){ $this->name = $name; $this->age = $age; } function show() { $str = 'my name is ' . $this->name . ' ' . $this->age; return $str; } } /* $sxd=new Person('sxd',22); $rsss = $sxd->show(); */ ?>
看一下这是你想要得结果吗?