php 构造函数中 引用

php 构造函数中 引用,第1张

你想问啥。

对象就是引用传递,你怎么传都是一个对象知道么?

$a =& new A(10);

这句多此一举, 这么写一样$a = new A(10);

想值传递或者说复制对象? 这么写 $a = new A(10);

$b = clone $a;

<php

class test{

        private $arr;

        function __construct(){

            $arr = array(

                'num' => '10001', // 学号

                'name' => 'test', // 姓名

                'class' => '班级' // 班级

            );

        }

        

        function _get(){

            return $this->arr;

        }

}

$test = new test();

echo '<pre>';

print_r($test->_get());

直接在实例化 class 类的时候传参数;

$a = new Class( $param1, $param2 );

public function __construct( $a, $b ) {

echo $a;

echo $b; // 可以这样在构造方法中输出来就看到了

}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/12188248.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-21
下一篇2023-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存