我在类中调用方法时出错

时间:2015-01-24 12:33:13

标签: php

我有一种检查一天是星期六或星期日的方法:

private static function isweekend($year, $month, $day)
    {
                    $time = mktime(0, 0, 0, $month, $day, $year);
                    $weekday = date('w', $time);
                    return ($weekday == 0 || $weekday == 6);
    }

我称之为:

$samedi_ou_dimanche = isweekend($annee,$mois,$jour);

我有这个错误:

  

致命错误:在第268行的/home/web1196/public_html/classes/Calendrier.class.php中调用未定义的函数isweekend()

上面的代码在一个类中:

class Calendrier
{
    private $db; // instance PDO

    public function __construct()
    {
        $this->db = PDO2::getInstance()->db;
    }
...

$samedi_ou_dimanche = isweekend($annee,$mois,$jour);
     echo $samedi_ou_dimanche;

        $html .= "\t\t\t\t\t\t\t\t<td id=\"AM_". $annee . '_' . $mois . '_' . $jour . "\" class=\"statutPeriode $statutAm";
        if ($_SESSION['utilisateur']->getRang() == "administrateur" || $statutAm == "libre" || ($statutAm == "proposé" && $idAm == $_SESSION['utilisateur']->getId())) $html .= $editable . $commentStatutAm;
        else $html .= $commentStatutAm;
        $html .= "\" style=\"background-color:$colorAm;\">$am</td>\n";
        $html .= "\t\t\t\t\t\t\t</tr>\n";

        // P.M.
        $html .= "\t\t\t\t\t\t\t<tr>\n";
        $html .= "\t\t\t\t\t\t\t\t<td class=\"periode\">P.M.</td>\n";
        $html .= "\t\t\t\t\t\t\t\t<td id=\"PM_". $annee . '_' . $mois . '_' . $jour . "\" class=\"statutPeriode $statutPm";
        if ($_SESSION['utilisateur']->getRang() == "administrateur" || $statutPm == "libre" || ($statutPm == "proposé" && $idPm == $_SESSION['utilisateur']->getId())) $html .= $editable . $commentStatutPm;
        else $html .= $commentStatutPm;
        $html .= "\" style=\"background-color:$colorPm;\">$pm</td>\n";
        $html .= "\t\t\t\t\t\t\t</tr>\n";


        $html .= "\t\t\t\t\t\t</table>\n";

        // affichage des données de debug
        $debug .= ob_get_clean();
        // $html .= "<div class=\"debug\">$debug&nbsp;</div>";

        return $html;
    }

    private static function isweekend($year, $month, $day)
    {
                    $time = mktime(0, 0, 0, $month, $day, $year);
                    $weekday = date('w', $time);
                    return ($weekday == 0 || $weekday == 6);
    }

}

2 个答案:

答案 0 :(得分:2)

在同一个班级中,使用:

$samedi_ou_dimanche = self::isweekend($annee,$mois,$jour);

建议阅读Classes and Objects Visibility

答案 1 :(得分:0)

尝试

$samedi_ou_dimanche = Calandrier::isweekend($annee,$mois,$jour);