www.webdeveloper.com
Results 1 to 4 of 4

Thread: how to change a CONSTANT defined in a class file?

  1. #1
    Join Date
    May 2005
    Posts
    16

    how to change a CONSTANT defined in a class file?

    Hi, I have the folowing php question:
    I have 3 files:

    the file a.php wich includes this php class: [ include "b.php"; ] (and more code...)
    the file b.php wich includes this other php class: [ require_once("c.php"); ] (and other functions of course...)
    and the file c.php wich has this definition: [ define('MAX_CUPS', 148); ] (and other definitions...)

    My question is how can I overwrite the defined "MAX_CUPS" value for instance if I need sometimes 148, sometimes 400, sometimes 800, etc.
    How cai I set this "MAX_CUPS" value again from the a.php file without having to edit the c.php file?
    I read that "A constant's value cannot be changed after it is set", but im triying to get help with this issue...

    Thanks indvance.

    Aldo.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    By definition, a constant is "constant". If you need it to be programatically variable, guess what? You need to use a variable, instead. So, if you want it to be variable, then you probably should redefine it as a variable instead of a constant in c.php.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2005
    Posts
    16
    this is a typical sample of code in a.php, so as you can see there are nothing to edit or there are no variables to redefine, because i dont know where in the b.php its calling the 'MAX_CUPS' defined in the c.php
    and i cannot edit the b.php and c.php because they are zend optimized.
    a question, zend is only a ctypter or it optimizes the runtime too?

    Code:
    <?php
    include "b.php";
    $cups = new cupsCreator();
    $cups->cupsSpec('MyCup1',0,0,120);
    $cups->cupsParse();
    ?>
    Aldo

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,148
    Is there some reason you cannot edit the c.php file?

    EDIT: Sorry, brain's a bit slow today - the explanation about the optimization didn't register on me for some reason.
    Last edited by NogDog; 06-14-2006 at 12:04 PM.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles