按提示输入出错了

来源:2-7 PHP类和对象之访问控制

北国风光

2015-06-06 13:19


 Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /543/zjM/index.php on line 17

写回答 关注

2回答

  • 晚安sp
    2015-06-06 15:40:03

    我试的没错,你再试试

    <?php
    class Car {
        private $speed = 0;
        
        public function getSpeed() {
            return $this->speed;
        }
        
        protected function speedUp() {
            $this->speed += 10;
        }
        
        //增加start方法,使他能够调用受保护的方法speedUp实现加速10
        public function start(){
            $this->speedUp();
        }
    
    
    }
    $car = new Car();
    $car->start();
    echo $car->getSpeed();


  • 道非空
    2015-06-06 14:57:33

    一般这种情况都是分号!

PHP进阶篇

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

181728 学习 · 2575 问题

查看课程

相似问题