PHP : call variable from another function in class

后端 未结 5 988
死守一世寂寞
死守一世寂寞 2021-01-24 21:14

This is my class code:

class myClass
{

   public function myFunc()
   {
      $myvar   =  \'Test str\';
   }

   public function result()
   {
      echo myClas         


        
5条回答
  •  孤独总比滥情好
    2021-01-24 21:26

    include "views.php";
    class Controller extends views{
    
        function index(){
            $this->head();  
            $this->home();
        }
        function privacy(){
            $this->head();
            $this->privc();
        }
        function about(){
            $this->head();
            $this->abt();
        }
        function address(){
            $this->head();
            $this->add();
        }
    }
    $obj=new Controller();
    
    if(isset($_GET['fun'])){
        $obj->$_GET['fun']();
    }
    else{
        $obj->index();  
    }
    
    
    
       This is views.php code
    
    
       class views{
        function head(){
            include "views/header.php";
            echo "
    this is header"; } function abt(){ include "views/about.php"; echo "
    This is about us page"; } function home(){ include "views/home.php"; echo "
    This is Home page"; } function privc(){ include "views/privacy.php"; echo "
    This is privacy page"; } function add(){ include "views/address.php"; echo "
    This is address page"; } }

提交回复
热议问题