为什么return的方法不行

来源:2-4 PHP类和对象之定义类的方法

fishfishmanman

2015-10-13 15:43

class Car {

    public $speed = 10;

    //增加speedUp方法,使speed加10

      function speedUp() {

        return ($speed+=100);

    }

}

$car = new Car();

echo $car->speedUp();

输出的结果是100

写回答 关注

2回答

  • 晚安sp
    2015-10-13 18:30:34
    已采纳
    <?php
    class Car {
        public $speed = 10;
        //增加speedUp方法,使speed加10
          function speedUp() {
            return ($this->speed+=100);
        }
    }
    $car = new Car();
    echo $car->speedUp();


    fishfi...

    非常感谢!

    2015-10-13 20:42:40

    共 1 条回复 >

  • zby5241
    2015-10-13 16:09:58

    gaode buchou

    zby524... 回复zby524...

    dsahkjfas

    2015-10-13 16:11:26

    共 2 条回复 >

PHP进阶篇

轻松学习PHP中级课程,进行全面了解,用PHP快速开发网站程序

181915 学习 · 2668 问题

查看课程

相似问题