Skip to content

Instantly share code, notes, and snippets.

@batazo
Last active May 29, 2021 20:00
Show Gist options
  • Select an option

  • Save batazo/ad8b44528283eccbfffd95141388109e to your computer and use it in GitHub Desktop.

Select an option

Save batazo/ad8b44528283eccbfffd95141388109e to your computer and use it in GitHub Desktop.
DateTimeImmutable vs Namespace
<?php
$datetime = new DateTimeImmutable();
$timestamp = $datetime->getTimestamp();
echo $timestamp;
// OUTPUT: Actual timestamp
<?php
namespace Application;
$datetime = new DateTimeImmutable();
$timestamp = $datetime->getTimestamp();
echo $timestamp;
// OUTPUT: Fatal ERROR
<?php
namespace Application;
$datetime = new \DateTimeImmutable();
$timestamp = $datetime->getTimestamp();
echo $timestamp;
// OUTPUT: Actual timestamp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment