Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,461
    Plugin Contributions
    29

    Default Correct method to add new define constant?

    If I want to use a new constant, for example in the moneyorder payment method,
    I could
    a) Add this constant to the original defines file
    b) Create an override file and add the constant there only
    c) Create an override file and add the constant there and in the original file
    d) Add it to a file in the extra_defines folder.

    These all seems to work correctly and previously I have always done b) but I suspect that is not correct as I have recently seen php error notices that indicate it cannot actually "see" that constant but assumes it (usually correctly).

    Would I be correct in saying the overrides file should only be used for overriding the original constants defined in the original language file and so d) is the correct option?

    thanks
    Steve

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Correct method to add new define constant

    Could you expand on what you mean by:
    These all seems to work correctly and previously I have always done b) but I suspect that is not correct as I have recently seen php error notices that indicate it cannot actually "see" that constant but assumes it (usually correctly).
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,461
    Plugin Contributions
    29

    Default Re: Correct method to add new define constant

    Well, while upgrading and cleaning up/fixing buglets I had the php error reporting set to -1/E_ALL.
    It generated a lot of notices referring to undefined variables and undefined and duplicated constants, most of which referred to stuff I had done, so I went about fixing them.

    I can only give you this example as I have fixed all the rest:

    [07-May-2010 20:49:12] PHP Notice: Use of undefined constant TEXT_NO_PRODUCTS - assumed 'TEXT_NO_PRODUCTS' in D:\My Documents\.....139b\includes\modules\CUSTOM\product_listing.php on line 315
    (This specific error will not appear on a default installation, it is due to a mod).

    All were due to the fact that I had added a new constant into an override file but not the original file. So I decided to put all new constants in one file in /extra_defines and only use the override files to redefine original constants. This fixed all the notices regarding undefined constants.

    While now it seems sort of obvious that new stuff should go in extra_defines, it also seemed logical many moons ago when I first set foot on the Zen road that they should go in the overrides file. Looking for such information now yields nothing written about it, hence my question to get something in print about it.

    At no point prior to this were there any real warnings or errors displayed, php always assumed correctly to use the new define in the override, but we all want an error-free shop don’t we, even the ones we can't see!

    Steve

  4. #4
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Correct method to add new define constant

    The answer is ... it depends.

    Some language overrides work by first loading the override file and then the original to plug any gaps, others by loading the override file in place of the original.

    For added confusion, there has been some shifting (for the better) between these approaches over the course of the 1.3 releases.

    Adding them in the original file only risks the addition being lost during an upgrade, and even if a file comparison is done, it still makes upgrades a bit harder as it mixes changes with core code and increases the number of changes that need to be analysed so a is not a good idea.

    Where files are overloaded it's only necessary to add new or changed terms. The best example of this are the main language files e.g. english.php (option b).

    When they're not overloaded just replaced (most common), you need to copy the entire file to the override folder and make any changes or additions there. This is the best option (c) when a defined constant is need only in one place or on one page and an override mechanism exists. That's not the case for the Admin, but I believe it is for payment modules.

    By extra_defines (d) I assume you mean extra_definitions (which in turn is different from extra_datafiles, which also contains define statements). These files are loaded for every page. There not strictly overrides but rather a different loading mechanism. Defines put in here will be loaded on every page, so it should really be used only if it is widely needed and doesn't clash with anything defined elsewhere.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  5. #5
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,461
    Plugin Contributions
    29

    Default Re: Correct method to add new define constant?

    Ha! I knew it wasn't straighforward.

    I think that goes some way to explaining why there are also a lot of notices generated in respect to constants defined more than once (usually in english.php and then somewhere else).

    Thanks for taking the time to write such a detailed description,

    Steve

 

 

Similar Threads

  1. v151 Constant define: BOX_ENTRY_CUSTOMERS
    By d0ugparker in forum General Questions
    Replies: 2
    Last Post: 16 Nov 2014, 01:47 AM
  2. define a constant text
    By janine in forum Addon Language Packs
    Replies: 5
    Last Post: 15 Dec 2011, 03:02 PM
  3. Wanting to add new constant in email....
    By pfabrick in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 2 Oct 2010, 05:29 AM
  4. Add New Page to Define Pages Editor?
    By noister in forum Customization from the Admin
    Replies: 3
    Last Post: 11 Nov 2009, 11:47 AM
  5. Define a global CONSTANT
    By dgsignal in forum General Questions
    Replies: 3
    Last Post: 20 Oct 2008, 06:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR