search

Home  >  Q&A  >  body text

php - A value is obviously assigned to variable A, but it is assigned to variable B. Why?

code show as below:

<?php
namespace Controller\Ip;
 
 class IpController{
     public $ip;
     public $key;
     public function Run(){
         $this->$ip = '111';
         $this->$key = '222';
         echo $this->$ip; //输出:222
     }

Why is the final output $this->$key? Looking for a solution, and I hope you can explain it, thank you very much

学习ing学习ing2778 days ago664

reply all(1)I'll reply

  • 淡淡烟草味

    淡淡烟草味2017-06-17 09:17:14

    <?php
    namespace Controller\Ip;
     
     class IpController{
         public $ip;
         public $key;
         public function Run(){
             $this->ip = '111';
             $this->key = '222';
             echo $this->ip;
         }

    reply
    0
  • Cancelreply