Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sugar2
    I read that "A constant's value cannot be changed after it is set"
    And that's pretty much it. If you need something you can change, use a variable instead.

  • #3
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i cannot change the 2 included php files they use functions wich make calls to that constant, the file that i can edit just do function calls so i cannot edit it and i cannot use variables there... thats for im looking a way for overwrite the constant value from the php file...

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    As Kid pointed out a constant is just that...constant. You cannot change it. That is the purpose of it in the programming world. That is why we have variables hence the value can vary or change. I still don't understand why you need to change a constant defined in another file. First of all why is it you cannot edit that other file containing the constant?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    http://www.php.net/manual/en/functio...t-redefine.php
    Don't expect to be able to use this on a normal server though.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by marek_mar
    http://www.php.net/manual/en/functio...t-redefine.php
    Don't expect to be able to use this on a normal server though.
    They would need the runkit package installed on the server in order to use any of those functions.
    http://pecl.php.net/package/runkit


    And I think their summary describes this perfectly.
    For all those things you.... probably shouldn't have been doing anyway....
    That package just encourages abuse and promotes bad programming.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    The package is the work of satan.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #9
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by marek_mar
    http://www.php.net/manual/en/functio...t-redefine.php
    Don't expect to be able to use this on a normal server though.
    well, i cannot compile that .c package cause my webserver its a windows2003 based, not a *nix server...

  • #10
    New Coder
    Join Date
    May 2005
    Location
    California
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts
    the problem was solved defining the constants just before call the includes...

    thanks to all


  •  

    Posting Permissions

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