...

View Full Version : how to change a CONSTANT defined in a class file?



sugar2
06-14-2006, 01:37 AM
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.

Kid Charming
06-14-2006, 01:45 AM
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.

sugar2
06-14-2006, 01:59 AM
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...

Spookster
06-14-2006, 02:23 AM
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?

marek_mar
06-14-2006, 11:41 AM
http://www.php.net/manual/en/function.runkit-constant-redefine.php
Don't expect to be able to use this on a normal server though.

Spookster
06-14-2006, 03:09 PM
http://www.php.net/manual/en/function.runkit-constant-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.

marek_mar
06-14-2006, 03:19 PM
The package is the work of satan.

sugar2
06-14-2006, 05:48 PM
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

sugar2
06-14-2006, 10:34 PM
http://www.php.net/manual/en/function.runkit-constant-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...

sugar2
07-20-2006, 06:33 PM
the problem was solved defining the constants just before call the includes...

thanks to all



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum