<?php class Page{ public $content; public $title = 'My Web Site'; public $keywords = 'keywords'; public $buttons = array( 'Home' => 'home.php', 'Contact' => 'contact.php', 'Services' => 'services.php', 'Site Map' => 'map.php' ); public function __set($name,$value){ $this->$name = $value; print_r($this); } } $page = new Page(); $page->__set('a333','12312'); echo $page->a333;
The above introduces PHP's use of variable functions to dynamically expand the attributes of classes, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.