zang8027 Posted February 3, 2009 Share Posted February 3, 2009 I got functions.php and addToCart.php. I grab a value being passed and setting it to restID. Then, i pass the value in a function to functions.php and try to set it to a constant. When i try to trace out the value of the constant on addToCart, it says, cannot find constant Function.php <?PHP //**************Function get shopping cart********************* function get_shopping_cart($restID) { if (! isset($_SESSION['cart'])) { return new ShoppingCart(); DEFINE('restIDConst',$restID); return 'restIDConst'; }else{ return unserialize($_SESSION['cart']); } }?> AddToCart <?php require_once '../functions/Functions.php'; $restID = $_REQUEST['restId']; $shopping_cart = get_shopping_cart($restID); echo constant('restIDConst'); ?> isn't the scope global for a constant? Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/ Share on other sites More sharing options...
trq Posted February 3, 2009 Share Posted February 3, 2009 return exits the function immediately, returning the expression on the right of itself. Your constant is never defined. Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753096 Share on other sites More sharing options...
zang8027 Posted February 3, 2009 Author Share Posted February 3, 2009 can i return 2 values out of the same function then? Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753114 Share on other sites More sharing options...
trq Posted February 3, 2009 Share Posted February 3, 2009 can i return 2 values out of the same function then? No. You can however return an array of values. Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753123 Share on other sites More sharing options...
zang8027 Posted February 3, 2009 Author Share Posted February 3, 2009 Here is why im trying to do this: later on, im using databases to pull info out of and its using the $restID. In my viewCart.php, there is no variable so the stuff being pulled out is not functioning. I want to say, when the session is created, create a constant. Then, when i go to viewCart.php, the constant is set and the database's are using the contstant to pull info out, thus eliminating the error. Later, i can say.. if($restID != restIDConst) { echo "you can not add items from other restaurants to same cart";} I am hoping this way will work out Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753126 Share on other sites More sharing options...
zang8027 Posted February 3, 2009 Author Share Posted February 3, 2009 btw, new ShoppingCart() is a class file that is being referenced by required_once. So i need to return a class and a value. Im stumped Link to comment https://forums.phpfreaks.com/topic/143547-constants-between/#findComment-753129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.