Do not understand this new $people ();

there is a piece of php code that simulates the hook mechanism

    class Ball{  
          public $people;
          public function down(){  
            echo    "ball is downing ";  
            //  
            $this->people=new Hook();
            $this->people->add("man");  
            $this->people->add("woman");  
        }  
          
        public function do(){  
            $this->people->exec();  
        }     
      
    }  
      
    //   
    class Hook{  
        private $hooklist = null ;  
        //   
        public  function add($people){         
            $this->hooklist[] =  new $people();        
        }  
        //   
        public function exec(){  
            foreach($this->hooklist as $people){  
                  $people->act();
            }  
              
        }  
    }  
    //   
    class man{  
        public function act(){  
            echo "nothing";  
        }     
    }  
      
    class woman{  
        public function act(){  
            echo "oh my god ";  
        }     
    }  
      
      
    $ball = new Ball();  
    $ball ->down();  
    $ball ->do();  
    

new $people()
people


        public  function add($people){         
        $this->hooklist[] =  new $people();        
    }  
Php
Jan.19,2022

can't you see that people is preceded by a $, which means it's just a variable, but the value of this variable may be an instance of a function with the new operation


$people = 'man'; , new $people (); is equivalent to new man ();

$people = 'woman'; , new $people (); is equivalent to new woman ();

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e479af-44c4b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e479af-44c4b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?