草庐IT

php - 获取父类中子类的实例

有什么方法可以在PHP中确定父类中的子实例吗?假设我们有这段代码:classParent{publicfunctionInstanceOfChild(){//Whattoputheretodisplay"ChildclassisinstanceofChildClass123"?}}classChildClass123extendsParent{//Somecodehere}我需要做的(如果可能的话)是创建方法InstanceOfChild()它将告诉我子类的实例,因为很多类都可以是我父类的子类,但我想要(比方说)记录哪个child调用了哪些方法。感谢您的帮助!

php - 您如何遍历当前类属性(不是从父类或抽象类继承的)?

我知道PHP5可以让您遍历类的属性。但是,如果该类扩展了另一个类,那么它也将包括在父类中声明的所有这些属性。这很好,没有什么可提示的。不过,我一直把SELF理解为指向当前类的指针,而$this也指向当前对象(包括从父类继承的东西)有什么方法可以只遍历当前类的属性。我问这个的原因....我正在使用CI并遍历$this包括大量我不需要的父属性。$m_val){echo"$s_key=>$m_val\n";}}}$o_child=newchild();$o_child->iterate()输出是s_parent=>Parentsezhi!s_child=>Childsezhi!s_fooba

php - 从父类调用扩展类函数

我是OOPHP的新手。有一些问题。classa{protectedfunctiona1(){...}}classbextendsa{publicfunctionb1(){...}}假设我们有2个类,如上所述。我正在调用b的方法,如下例所示classa{var$b;function__construct(){$b=newb();}protectedfunctiona1(){$b->b1();}}classbextendsa{publicfunctionb1(){...}}我知道,可以从扩展类调用父类的方法,但我想知道是否可以反向调用?我的意思是,从父类内部调用扩展类方法(在本例中,cla

php - 如何使用具有相同方法名称的父类方法的参数?

标题有点困惑,我知道,但这是我能做的最好的。=P希望有人能够提供帮助。我正在使用CodeIgniter,我在基类中有一个方法有多个参数:classMY_BaseextendsCI_Model{functionsome_function($param1,$param2...$param8){//dostuff}}我想做的基本上就是这个,在子类中:classChildextendsMY_Base{functionsome_function($param1,$param2...$param8){parent::some_function($param1,$param2...$param8);

php - 如何检查父类的instanceof?

在PHP中有两个类:classparentTroll{...}和classtrollextendsparentTroll{...}然后有一个对象$troll=newtroll();如何检查$trollinstanceofparentTroll?该行现在返回false。 最佳答案 以下示例返回true:classparentTroll{}classtrollextendsparentTroll{}$troll=newtroll();var_dump($trollinstanceofparentTroll);输出:booleantrue

php - 使用原则 2 选择从一个父类(super class)扩展的多个子类的实体

鉴于我的Doctrine2实体的设置:App\Bundle\LorumBundle\Entity\Node:type:entitytable:nodefields:id:id:truetype:integerunsigned:falsenullable:falsegenerator:strategy:IDENTITYcreated:type:datetimeinheritanceType:SINGLE_TABLEdiscriminatorColumn:name:typetype:stringlength:255discriminatorMap:a:ab:bc:cApp\Bundle\L

java - 了解使用 Super 访问父类(super class)成员

我是引用java语言规范来理解super的使用。虽然我了解第一个用例,即Theformsuper.IdentifierreferstothefieldnamedIdentifierofthecurrentobject,butwiththecurrentobjectviewedasaninstanceofthesuperclassofthecurrentclass.我似乎无法理解以下用例:TheformT.super.IdentifierreferstothefieldnamedIdentifierofthelexicallyenclosinginstancecorrespondingt

java - 泛型 Java 类型的类不能分配给其类类型上限为泛型父类(super class)型的变量

我使用Java8。在我的设计中有一些简单的类,它们对值参数进行建模,例如FloatParameter。或EnumParameter.A具有这些类的通用父类(superclass)(GenericParameter),它实现了参数名称及其默认值。子类实现其他特定于它们的属性,例如FloatParameter的范围。.此外,我想处理参数的类型,而不考虑它们的具体类型。但我仍然想以它们是GenericParameter的子类型的方式来绑定(bind)类型.为此,我创建了一个方法,例如process(Class>paramType).现在,问题是EnumParameter.class不能分配给

java - Java 转 Scala,如何处理调用父类(super class)构造函数?

问题摘要-如何将其转换为Scala类?问题-多个构造函数调用不同的super构造函数Java类-publicclassClassConstExampleextendsBaseClassExample{privateStringxyzProp;privatestringinType="def";privateStringoutType="def";privateStringflagSpecial="none";publicClassConstExample(finalStringfile,finalStringheader,finalStringinType,finalStringout

java - 如何在 playframework 中从父类(super class)继承模型

我想了解继承是如何发挥作用的!但还没有成功。所以,我有这样的父类(superclass):@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)abstractclassSuperClassextendsModel{@Id@GeneratedValue(strategy=GenerationType.TABLE,generator="SEQ_TABLE")@TableGenerator(name="SEQ_TABLE")Longid;inttestVal;}还有2个继承类:@EntitypublicclassSubextendsSu