这是用面向对象写的判断年份是不是闰年。可是它会报错,而且不管输入什么年份,都判断为闰年

解决方案 »

  1.   

    Analysis 方法中的 $year 都应为 $this->year
      

  2.   

    Analysis方法改成这样
    function Analysis(){
    if($this->year%4==0 && $this->year%100!=0 || $this->year%400==0){
    echo $this->year.'为闰年';
    }else{
    echo $this->year.'不是闰年';
    }
    }
      

  3.   

    少年,你应该这么写 
    https://tools.vaptu.com/online/shared/65a481d2e3f5430d380fb297fc9eb5b4
      

  4.   

    你的year是类属性,应该用$this->year调用,改为这样就可以了function Analysis(){
        if($this->year%4==0 && $this->year%100!=0 || $this->year%400==0){
            echo $this->year.'为闰年';
        }else{
            echo $this->year.'不是闰年';
        }
    }
      

  5.   

    你的year是类属性,应该用$this->year调用