//定义继承于Car的Truck类
class Truck extends Car{
public function speedUp(){
$this -> speed = parent::speedUp()+50;
return $this ->speed;
}
}
class Truck extends Car{
public function speedUp(){
$this -> speed = parent::speedUp()+50;
return $this ->speed;
}
}
2016-04-07
Error:wrong
#0 {main}
异常行号:3
所在文件:/26/603/8whB/index.php
Warning: file_put_contents(error.log): failed to open stream: Read-only file system in /26/603/8whB/index.php on line 11
#0 {main}
异常行号:3
所在文件:/26/603/8whB/index.php
Warning: file_put_contents(error.log): failed to open stream: Read-only file system in /26/603/8whB/index.php on line 11
2016-04-07
默认都为public,外部可以访问。一般通过->对象操作符来访问对象的属性或者方法,对于静态属性则使用::双冒号进行访问。当在类成员方法内部调用的时候,可以使用$this伪变量调用当前对象的属性。
2016-04-06
最赞回答 / YunsChou
return $a+$b;你可以拆为两句代码来理解:$c = $a + $b;return $c;那么这个方法可以转换成这样:function sum($a, $b){$c = $a + $b;return $c; }我们通过读代码来解析下这个方法的意思:将传入的参数$a和$b相加得到的值为$c,即将$c的值作为这个方法的返回结果分割线-----当调用echo sum(1,2);这个方法时,其实也可以拆分为2步:第一步:$c = sum(1, 2);{方法内部相当于$c = 1 + 2;return $c...
2016-04-05
<?php
class Car {
static function speed(){
return 0;
}
}
echo Car :: speed()+10;
class Car {
static function speed(){
return 0;
}
}
echo Car :: speed()+10;
2016-04-05
<?php
class Car {
public $speed = 0;
//增加speedUp方法,使speed加10
function speedUp($num){
return $this->speed+=$num;
}
}
$car = new Car();
$car->speedUp(10);
echo $car->speed;
class Car {
public $speed = 0;
//增加speedUp方法,使speed加10
function speedUp($num){
return $this->speed+=$num;
}
}
$car = new Car();
$car->speedUp(10);
echo $car->speed;
2016-04-05