Another year it still deserves saying… It’s long been clear the risks and harms of cannabis use are mild, and with that knowledge it should sicken us that people are regularly pulled into our criminal justice system because of cannabis use, sales, production, or political speech (see the example made of Marc Emery). Shame on us for keeping these unjustifiable laws on the books due to ignorance and inertia; each year they harm individuals far more than use of the drug, further erode our Fourth Amendment protections, and place otherwise law-abiding citizens at odds with the police.
Month: April 2012
Define namespace constants using expressions
Since const
is parsed at compile-time, you can’t use expressions in namespace constants, but you can use define
as long as the name argument is the full name from the global scope (run this):
namespace Foo\Bar;
const CONST1 = 1;
define('CONST2', 1 + 1); // global
define(__NAMESPACE__ . '\\CONST3', 1 + 1 + 1); // in namespace!
echo CONST1, " ", \CONST2, " ", CONST3; // echos '1 2 3'
The bad: PHPStorm comprehends const
and global define
s, but not define(__NAMESPACE__ . '\\CONST', $value)
PHP RFC Preview: Dynamic Callback Expressions
I’m posting this to get some initial feedback on this idea before I officially submit an RFC.
Background
Even with PHP’s growing object-oriented and functional programming features, the callback remains widely-used and useful. However, forcing authors to create callbacks via strings and arrays presents difficulties:
- Most IDEs do not recognize callbacks as such, and so cannot offer autocompletion, rename refactoring, and other benefits of code comprehension.
- Authors can misspell identifiers inside strings.
- Within namespaced code, authors can forget to prepend the namespace, since function calls within the namespace do not require it.
- Where
use
statements change the identifier for a class, authors can specify the local classname instead of the fully resolved name.