English 中文(简体)
考古方法+反射镜 = 能够对阶级特性进行调查。 为什么?
原标题:Magic methods + Reflection API = can t investigate class properties. Why?

如果我使用魔法。 在使用APICES的同时,我可以调查同类财产。 为什么如此?

http://www.ohchr.org。

反应性反应是什么? 插头并不是指我所理解的。 页: 1

最佳回答

使用魔法来获取财产,这些财产通常不在类别定义中。

您的班级定义一般会考虑:

class MyClass {
    private $data;
    public function __get($name) {
        return $this->data[$name];
    }
    public function __set($name, $value) {
        $this->data[$name] = $value;
    }
}


As there is no real properties -- there is on only a $data array, which will be used by the magic methods __get an __set as a big data-store -- those cannot be seen by the Reflection API.

这是使用魔法造成的一个问题: 它们用于获取(或方法,>>-bet<>>>>>>>>,而“反思”仅能看到其中的内容。

问题回答

可能的解决办法是增加数据的范围,以保护:

class MyClass {
    protected $data;
    public function __get($name) {
        return $this->data[$name];
    }
    public function __set($name, $value) {
        $this->data[$name] = $value;
    }
}

这样,扩大的班级就能够进入阵列,因为它们认为合适,并收集经期确定的财产。





相关问题
Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Passing another class amongst instances

I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...