Home > Backend Development > PHP Tutorial > php-php进阶 - php如何写一个简单的类的拓展?

php-php进阶 - php如何写一个简单的类的拓展?

WBOY
Release: 2016-06-06 20:12:46
Original
1162 people have browsed it

目前只会写一个函数,我想写个简单的类。

回复内容:

目前只会写一个函数,我想写个简单的类。

<code><?php /**
 * 我是个类
 */
class person
{    
    /**
     * 我的手
     */
    private $_hand = 'myhand';

    /**
     * 我会吃饭
     */
    public function eat($food)
    {
        echo 'i eat'.$food;
    }
}



</code></code>
Copy after login

<code><?php class 我是加法

{
    
    function __construct($a,$b)
    {
    $this->a=$a;
    $this->b=$b;
    }



    function __toString()
    {
        $c=$this->a+$this->b;
        $c=strval($c);
        return $c  ;
    }



}


echo new 我是加法(1,2);</code>
Copy after login
Related labels:
php
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