CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Cannot redeclare class CRM_Utils_Date
Pages: [1]

Author Topic: Cannot redeclare class CRM_Utils_Date  (Read 981 times)

Hershel

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4640
  • Karma: 176
    • CiviHosting
  • CiviCRM version: Latest
  • CMS version: Mostly WordPress and Drupal
Cannot redeclare class CRM_Utils_Date
February 15, 2011, 06:41:22 am
I tried to customize CRM/Utils/Date.php using a custom PHP directory on a Drupal site and I get:

Code: [Select]
Fatal error: Cannot redeclare class CRM_Utils_Date in /home/mysite/www/www/sites/all/custom.code/CRM/Utils/Date.php on line 41

I think I recall this issue with earlier versions--this site is 3.3.5 anyhow.
CiviHosting and CiviOnline -- The CiviCRM hosting experts, since 2007

See here for the official: What to do if you think you've found a bug.

torenware

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 4
Re: Cannot redeclare class CRM_Utils_Date
February 17, 2011, 03:05:17 pm
Overrides won't work with some classes, because they get loaded from the regular tree too early in the bootstrapping process for CiviCRM to know about a setting pulled from the DB.  CRM_Utils_Date is a pretty fundamental class, I'm guessing this is your problem here.

I'd guess the problem is in CRM/Core/DAO.php, since that file loads CRM/Utils/Date.php high up in the file in global scope.  So the Date class is defined before the database is ever loaded.

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Cannot redeclare class CRM_Utils_Date
February 17, 2011, 07:54:54 pm
Write a class that extends Date.
Then in the buildform hook replace object instances of Date contained in the form instance with one of your object instances.

Haven't fully thought it through but I'm running on lack of sleep and that's the best I can offer at the moment. Pseudo-code:

Code: [Select]
foreach date instance in the form {
  $mydate = new MyDate(existing date instance);
  $form->existing_date_instance = $mydate;
}

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Cannot redeclare class CRM_Utils_Date

This forum was archived on 2017-11-26.