Seems like PHP 5 added some cool stuff, but I can't find the API for it.
For example, I see reference to a DateTime class in the date/time functions in the php documentation, but no link to the DateTime API. Is it something in pecl? or pear? What did I miss?
Thanks in advance!There is a link in the user-supplied notes of the date_create() page that may be of use: <!-- m --><a class="postlink" href="http://laughingmeme.org/2007/02/27/PS">http://laughingmeme.org/2007/02/27/PS</a><!-- m -->: I ran this...
<?php
header('Content-Type: text/plain');
Reflection::export(new ReflectionClass('DateTime'));
...which output this...
Class [ <internal:date> class DateTime ] {
- Constants [11] {
Constant [ string ATOM ] { Y-m-d\TH:i:sP }
Constant [ string COOKIE ] { l, d-M-y H:i:s T }
Constant [ string ISO8601 ] { Y-m-d\TH:i:sO }
Constant [ string RFC822 ] { D, d M y H:i:s O }
Constant [ string RFC850 ] { l, d-M-y H:i:s T }
Constant [ string RFC1036 ] { D, d M y H:i:s O }
Constant [ string RFC1123 ] { D, d M Y H:i:s O }
Constant [ string RFC2822 ] { D, d M Y H:i:s O }
Constant [ string RFC3339 ] { Y-m-d\TH:i:sP }
Constant [ string RSS ] { D, d M Y H:i:s O }
Constant [ string W3C ] { Y-m-d\TH:i:sP }
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [0] {
}
- Methods [9] {
Method [ <internal, ctor> public method __construct ] {
}
Method [ <internal> public method format ] {
}
Method [ <internal> public method modify ] {
}
Method [ <internal> public method getTimezone ] {
}
Method [ <internal> public method setTimezone ] {
}
Method [ <internal> public method getOffset ] {
}
Method [ <internal> public method setTime ] {
}
Method [ <internal> public method setDate ] {
}
Method [ <internal> public method setISODate ] {
}
}
}In other words, the functions prefixed with "datetime_" are procedural versions of the methods. E.g., date_format is described as
string date_format ( DateTime $object , string $format )
string DateTime::format ( string $format )
So you can either create a DateTime object and pass it as an argument to date_format(), or you can call its format() method - either would do.In a slight side note; What does the <internal> mean in the output from the reflection class?
Method [ <internal> public method setTime ] {
}
Can you have external methods?I'm not sure what it means, but from some of the examples on the reflection page, the implication is that the alternative to "internal" is "user-defined".In other words, the method is implemented internally in C as part of the extension, rather than as part of a class written in PHP.On a vaguely similar note, this does not seem possible:
function do_something() throws Exception
{
// ...
}
and the alternative might be simply this:
/**
* @throws Exception
*/
function do_something()
{
// ...
}
which is fine for documentation, but doesn't "enforce" the contract.
Can anyone point me in the right direction here if I'm wrong? Thanks.I don't think there is a way of enforcing it. I'm quite glad of that otherwise before we knew it we'd be programming Java.
For example, I see reference to a DateTime class in the date/time functions in the php documentation, but no link to the DateTime API. Is it something in pecl? or pear? What did I miss?
Thanks in advance!There is a link in the user-supplied notes of the date_create() page that may be of use: <!-- m --><a class="postlink" href="http://laughingmeme.org/2007/02/27/PS">http://laughingmeme.org/2007/02/27/PS</a><!-- m -->: I ran this...
<?php
header('Content-Type: text/plain');
Reflection::export(new ReflectionClass('DateTime'));
...which output this...
Class [ <internal:date> class DateTime ] {
- Constants [11] {
Constant [ string ATOM ] { Y-m-d\TH:i:sP }
Constant [ string COOKIE ] { l, d-M-y H:i:s T }
Constant [ string ISO8601 ] { Y-m-d\TH:i:sO }
Constant [ string RFC822 ] { D, d M y H:i:s O }
Constant [ string RFC850 ] { l, d-M-y H:i:s T }
Constant [ string RFC1036 ] { D, d M y H:i:s O }
Constant [ string RFC1123 ] { D, d M Y H:i:s O }
Constant [ string RFC2822 ] { D, d M Y H:i:s O }
Constant [ string RFC3339 ] { Y-m-d\TH:i:sP }
Constant [ string RSS ] { D, d M Y H:i:s O }
Constant [ string W3C ] { Y-m-d\TH:i:sP }
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [0] {
}
- Methods [9] {
Method [ <internal, ctor> public method __construct ] {
}
Method [ <internal> public method format ] {
}
Method [ <internal> public method modify ] {
}
Method [ <internal> public method getTimezone ] {
}
Method [ <internal> public method setTimezone ] {
}
Method [ <internal> public method getOffset ] {
}
Method [ <internal> public method setTime ] {
}
Method [ <internal> public method setDate ] {
}
Method [ <internal> public method setISODate ] {
}
}
}In other words, the functions prefixed with "datetime_" are procedural versions of the methods. E.g., date_format is described as
string date_format ( DateTime $object , string $format )
string DateTime::format ( string $format )
So you can either create a DateTime object and pass it as an argument to date_format(), or you can call its format() method - either would do.In a slight side note; What does the <internal> mean in the output from the reflection class?
Method [ <internal> public method setTime ] {
}
Can you have external methods?I'm not sure what it means, but from some of the examples on the reflection page, the implication is that the alternative to "internal" is "user-defined".In other words, the method is implemented internally in C as part of the extension, rather than as part of a class written in PHP.On a vaguely similar note, this does not seem possible:
function do_something() throws Exception
{
// ...
}
and the alternative might be simply this:
/**
* @throws Exception
*/
function do_something()
{
// ...
}
which is fine for documentation, but doesn't "enforce" the contract.
Can anyone point me in the right direction here if I'm wrong? Thanks.I don't think there is a way of enforcing it. I'm quite glad of that otherwise before we knew it we'd be programming Java.