Home > Backend Development > PHP Tutorial > PHP uses variable functions to dynamically expand class attributes

PHP uses variable functions to dynamically expand class attributes

WBOY
Release: 2016-07-29 09:02:19
Original
1136 people have browsed it
<?php
class Page{
    public $content;
    public $title = &#39;My Web Site&#39;;
    public $keywords = &#39;keywords&#39;;
    public $buttons = array(
        &#39;Home&#39; => '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;
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template