我有一个类Convert
,其函数为date
:
<?php
class Convert{
public static function datum($timestamp = time()){
//When $timestamp isn't set use php function time()
return(date("N" , $timestamp));
}
}
?>
//run method
Convert::datum();
这不起作用我收到了一个错误:
Parse error: syntax error, unexpected '(', expecting ')' in .... on line 3 (function line)
;看起来功能时间没有重新调整。
答案 0 :(得分:2)
更改
class Convert{
public static function datum($timestamp = time()){ // <-- no functions allowed in here
//When $timestamp isn't set use php function time()
return(date("N" , $timestamp));
}
}
向
class Convert{
public static function datum($timestamp = NULL){
//When $timestamp isn't set use php function time()
$timestamp = ($timestamp !== NULL ? $timestamp : time());
return(date("N" , $timestamp));
}
}
声明函数时,参数只能接受空数据类型或数据。该参数不能设置为接受函数的返回,也不能是动态的。
不可强>
public static function datum($timestamp = NULL){
public static function datum($timestamp = 13524564){
public static function datum($timestamp = '423432'){
public static function datum($timestamp = array()){
public static function datum($timestamp = FALSE){
public static function datum($timestamp = TRUE){
<强>为强>
public static function datum($timestamp = time()){
public static function datum($timestamp = (8*2)){
public static function datum($timestamp = $this->someValFromThisClass){
public static function datum($timestamp = 123, $new = $timestamp){