Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy. This forum is not for asking programming related questions.
<?php
define('one', 1); // one will be 1
const two = 2; // two will be 2 (as of php 5.3)
define('one_or_two', 1 | 2); // one_or_two will be 3
const two_or_three = 2 | 3; // error
?>
This is quite annoying, because I need to use the or operator in one of my class constants. I could just add the values up...but this makes more sense - next time I go back to look over my code, instead of seeing a random number and wondering what it's for, I'll see the comparison.
So yeah, has anyone ever come across something similar, or even better, know a way to fix it?
What do you want to happen? Performing a bitwise OR (1 | 2) is 3. If you need to use the expression 1 | 2 then it needs to be a string:
define('one_or_two', '1 | 2');
-Shawn
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Yeah, it is inconvenient that they would treat them differently, but classes, class constants and functions are declared compile time, so they can have only constant values. Global constants declared with define() are declared runtime so they can take the result of an expression.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.