php8.5
Home/ Manual/ time / duration/ Time\Duration::__construct

Time\Duration::__construct

PHP function Edit on GitHub ✎

(PHP 8 >= 8.6.0)

Private constructor to disallow direct instantiation

Description

Time\Duration::__construct()

This private constructor prevents Time\Duration objects from being created with new. Use one of the factory methods instead, which make the unit of the given value explicit: Time\Duration::fromSeconds, Time\Duration::fromNanoseconds, Time\Duration::fromMicroseconds, Time\Duration::fromMilliseconds, Time\Duration::fromMinutes, Time\Duration::fromHours, or Time\Duration::fromIso8601DurationString.

Parameters Parameters

Errors/Exceptions

Attempting to instantiate the class with new throws an Error.

See Also

  • Time\Duration::fromSeconds
  • Time\Duration::fromIso8601DurationString

Source: reference/datetime/time/duration/construct.xml · from the official PHP manual (php/doc-en)