Forum Moderators: coopster

Message Too Old, No Replies

how to change a CONSTANT defined in a class file?

         

sugar2

1:00 am on Jun 14, 2006 (gmt 0)

10+ Year Member



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.

eelixduppy

1:20 am on Jun 14, 2006 (gmt 0)



The reasons for constants are so that you cannot change their values. Why don't you just use a global [us3.php.net] variable?

sugar2

4:49 pm on Jun 14, 2006 (gmt 0)

10+ Year Member



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?

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

Aldo

coopster

2:08 am on Jun 18, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've run into this problem before and created my own workaround. Check to see if a variable exists and if so, use that value in the constant instead.
define('MAX_CUPS', ((isset($MAX_CUPS)) ? $MAX_CUPS : 148));

Of course, this means you will have to have set the variable $MAX_CUPS somewhere in your code prior to this constant definition.