<?php $instest = new test();
$insobject = new object();
$insobject->objectValue = "final";
$instest->test(); class test{
var $testValue = "testValueins";
function test(){
print_r($insobject);
$insobject->hello();
}
} class object{
var $objectValue = "original";
function hello(){
echo $objectValue;
}
}?>报错如下Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 11
Call Stack
Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 12
Fatal error: Call to a member function hello() on a non-object in C:\wamp\www\zhebo\test.php on line 12这有什么问题么,怎样才可以达到在实例里引用别的实例里的方法,或者有什么更好地解决方法?
我很急,希望大家可以帮忙。非常感谢啊。非常紧急。第一次用对象的思想编程还不太懂啊。
$insobject = new object();
$insobject->objectValue = "final";
$instest->test(); class test{
var $testValue = "testValueins";
function test(){
print_r($insobject);
$insobject->hello();
}
} class object{
var $objectValue = "original";
function hello(){
echo $objectValue;
}
}?>报错如下Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 11
Call Stack
Notice: Undefined variable: insobject in C:\wamp\www\zhebo\test.php on line 12
Fatal error: Call to a member function hello() on a non-object in C:\wamp\www\zhebo\test.php on line 12这有什么问题么,怎样才可以达到在实例里引用别的实例里的方法,或者有什么更好地解决方法?
我很急,希望大家可以帮忙。非常感谢啊。非常紧急。第一次用对象的思想编程还不太懂啊。
$insobject = new object(); //$insobject->objectValue = "final";
object::$objectValue= "final";
$instest->test(); class test{
var $testValue = "testValueins";
function test(){
object::hello();
}
} class object{
public static $objectValue = "original";
Public static function hello(){
echo self::$objectValue.'<br>';
}
}
这是 php 语法的基本规则,不可逾越$insobject = new object();
$insobject->objectValue = "final";$instest = new test($insobject);//$instest->test(); 这是构造函数,一般不这样调用
class test{
var $testValue = "testValueins";
function test($insobject){
print_r($insobject);
$insobject->hello();
}
}
class object{
var $objectValue = "original";
function hello(){
echo $this->objectValue; //访问属性要这样
}
}
object Object ( [objectValue] => final ) final
那我现在应该怎么在外部调用 test里的test函数呢,如果一般不这样使用的话
那我现在应该怎么在外部调用 test里的test函数呢,如果一般不这样使用的话另外构造函数不是 __construct()么?
都是返回一个类的实例
那我现在应该怎么在外部调用 test里的test函数呢,如果一般不这样使用的话另外构造函数不是 __construct()么?我想起来了,php4里同名函数默认是构造函数
那我现在应该怎么在外部调用 test里的test函数呢,如果一般不这样使用的话另外构造函数不是 __construct()么?我想起来了,php4里同名函数默认是构造函数