DateTimeZone exception?

Hi,

I have a piece of code under SugarPro/custom/clients/base/api/Tasks.php

$utcTime = new DateTime("now", new DateTimeZone("UTC"));

it work fine, however when I use the same code in another file SugarPro/custom/modules/Quotes/custom_classes/QuoteNotify.php

it will throw exception, the exception is caused by "new DateTimeZone("UTC")"

The only different I noticed is that below two line is included in QuoteNotify.php

namespace Sugarcrm\Sugarcrm\custom\modules\Quotes\custom_classes;
use DateTime;

I just wonder why the exception error in QuoteNotify.php?

Any suggestion would be appreciated.

Parents
  • When using namespace, all classes not defined by anyone of the namespaces need to have "\" as prefix, like:

    $utcTime = new \DateTime("now", new \DateTimeZone("UTC"));

    or

    $utcTime = new DateTime("now", new \DateTimeZone("UTC"));

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Thank you so much Jeroen, Andre

    It work after adding the backslash. It's seem I need to have a look the PHP:namespace Manual.

Reply Children
No Data