[Eval not required] can be implemented? Solution

Source: Internet
Author: User
[Eval not required] can be implemented? & Lt ;? PhpclassRef {public $ x = '000000'; publicfunction _ construct () {echo 'Father ';} can publicfunctionreftest () {$ fun = 'Test [eval not needed] be implemented?
Class Ref {
Public $ x = '000000 ';
Public function _ construct (){
Echo 'Father ';
}

Public function reftest (){
$ Fun = 'test ';
$ Ss = '$ this-> Y ';
$ Funstr = '$ this->'. $ fun. '('. $ ss .');';
Echo $ funstr;
Echo'
';
Eval ($ funstr );
}

}
----------------------------------------

Require 'ref. php ';
Class SonRef extends Ref {
Public $ y = array ('A', 'B', 'C ');
Public function test ($ str ){
Print_r ($ str );
}

}

$ K = new SonRef ();
$ K-> reftest ();

------ Solution --------------------
The program may not be light. Both SonRef and GirlRef share the non-private method of the parent class fairly.
------ Solution --------------------
$ Fun = 'test ';
$ Ss = '$ this-> Y ';
$ Funstr = '$ this->'. $ fun. '('. $ ss .');';
Eval ($ funstr );

Yishu
$ Fun = 'test ';
$ This-> $ unn ($ this-> y );

------ Solution --------------------
No matter who it comes from, since you can write $ this-> y, it means that y is already yours.

I feel that your thinking is a bit messy. can you calm down and carefully describe your needs?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.