php中类的属性声明时赋值一定是一个直接的值,不能是函数返回值,表达式,以及通过"."连接起来的字符串,如果偏要用这些赋值,可以通过构造函数__construct();

<?php

class Human{

    public static $leg=2;  //类的静态属性,只属于全类,不属于某个对象,不能被对象调用

    public $iq; //声明了类的属性默认赋值为null

    public $age;

    public $name;

    //public $iq=rand(80,120);//这种写法错误

    //public $age=30>20;//这种写法错误

    //public $name="zhang"."san";//这种写法错误

    public function __construct(){

        $this->iq=rand(80,120);

        $this->age=30>20;

        $this->name="zhang"."san";

}

}