Key Parameter Issues

I just started learning PHP, and I have some questions about parameters. Consider DateTime class PHP DateTime Class Manual

public __construct ([ string $time = "now" [, DateTimeZone $timezone = NULL ]] )
public DateTime setDate ( int $year , int $month , int $day )

Here is my question:

  • Why are the parameters in the constructor in brackets when the parameters are setDatenot in brackets?
  • Why is there a parenthesis inside the parenthesis?
  • Why is there a comma before the open bracket [,?

Thanks in advance.

+3
source share
2 answers
  • Parameters in brackets are optional. Therefore, if I initialize the DateTime class and do not provide a second parameter, it takes a default value null.

  • : DateTime, 1, 1 2, . 1, 2.

  • , 1.

+1
  • .
  • .
  • .
+4

All Articles