Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php:自定义类型的属性_Php_Properties - Fatal编程技术网

php:自定义类型的属性

php:自定义类型的属性,php,properties,Php,Properties,我正在尝试编写以下代码,虽然它是错误的,但它可能会最好地说明我为什么要这么做 class myClass { private $name = ""; private $startAddress = new myAddress(); // this is the issue private $endAddress = new myAddress(); // this is the issue } 我怎样才能正确地做到这一点 谢谢你@alex:如果你忽略了可见性,p

我正在尝试编写以下代码,虽然它是错误的,但它可能会最好地说明我为什么要这么做

class myClass
{
    private $name = "";
    private $startAddress = new myAddress();  // this is the issue
    private $endAddress = new myAddress();    // this is the issue
}
我怎样才能正确地做到这一点


谢谢你

@alex:如果你忽略了可见性,
public
。@KingCrunch我想展示一下。否则我会觉得我还在用PHP4:p非常感谢大家!反应如此迅速!这是一个很大的帮助。再次感谢!:)@亚历克斯:如果你忽略了可见性,
public
是假定的。@KingCrunch我想展示一下。否则我会觉得我还在用PHP4:p非常感谢大家!反应如此迅速!这是一个很大的帮助。再次感谢!:)
 <?php
class myClass {
   private $endAddress;
   public function __construct() {
       $this->endAddress = new myAddress();
   }
 }