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) »
  • Classes which cannot be overriden
Pages: [1]

Author Topic: Classes which cannot be overriden  (Read 1027 times)

mantas

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: drupal 6
  • MySQL version: 5.1
  • PHP version: 5.3
Classes which cannot be overriden
April 04, 2012, 06:39:24 am
Hi

I haven't find info about it so posting here. While refactoring code and debugging I find out that some core classes cannot be overridden.
It happens because set_include_path is at 228 line in Config php and all classes which were included cannot be overridden.
#in Config php
require_once 'Log.php';
require_once 'Mail php';

require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/System.php';
require_once 'CRM/Utils/File.php';
require_once 'CRM/Core/Session.php';
require_once 'CRM/Core/Config/Variables.php';
require_once 'api/api.php';

#in Dao.php
require_once 'PEAR.php';
require_once 'DBDataObject.php';

require_once 'CRM/Utils/Date.php';
require_once 'CRM/Core/I18n.php';
require_once 'CRM/Core/PseudoConstant.php';
I tried to include list of files code tag, but was getting "Sorry, you are not allowed to post external links. " Even I remove all / and .

Any comments on that?

Its good idea not to allow to override main classes, but in my project while refactoring code I found some code changes in core dir

Thanks
Mantas
« Last Edit: April 04, 2012, 06:46:07 am by mantas »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Classes which cannot be overriden
April 04, 2012, 09:55:25 am
Hi,

By overridden, you mean re-defined in the custom code folder, right?

In general, do seriously try every single other option before going that road. It will be a problem in an upgrade if the code of that re-defined class change. And given the speed of changes on civi, it's not if you're going to have a problem, but when.

Between hooks/api & templates, you can re-define a lot of things. Do the changes that way, it's worthwhile.

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Classes which cannot be overriden
April 04, 2012, 02:32:25 pm

Note that in 4.2 we've switched to using php autoloading, so a lot of the below require's disappear and hence over-riding them is possible

however xavier is right, and u should not override civicrm .php files

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

mantas

  • I’m new here
  • *
  • Posts: 4
  • Karma: 0
  • CiviCRM version: 4.1
  • CMS version: drupal 6
  • MySQL version: 5.1
  • PHP version: 5.3
Re: Classes which cannot be overriden
April 05, 2012, 02:32:53 pm
Thank you for replies. It all makes sense.
Yes I meant re-defining. Problem is that I'm refactoring code and switching from 3.2 to 4.1. And there are lots of re-defined core files and ones which cannot be re-defined were changed directly. I hope I will be able move all functionality to custom classes :)

Thanks
Mantas

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Classes which cannot be overriden
April 06, 2012, 01:01:20 am
Not sure what you mean by custom classes, but I'd strongly suggest you to spend time reading our book about custom dev.

http://book.civicrm.org/developer/

If you do it the same way as you/the initial author has done it on your 3.2, you will have (or your successor) the same issues.

Do yourself a favour and use hooks & api, don't do custom classes.

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Classes which cannot be overriden

This forum was archived on 2017-11-26.