I use a variety of programming languages. I like it when the syntax features start to converge, as this lets me hack faster (I will then write it properly when I understand the requirements better). In my more flexible languages, I use structures that would make any Cobol or Fortran person wince; as they are more flexible, so meeting requirements better. The below code is technically how Perl works, other than you are likely to be able to see the non public variables. I do know what a lambda function is, but rarely use them in PHP ~ I do in JS though.

As PHP borrows computational theory from C, sticking to the standard C way of doing things would seem easier. Having a fixed reference (set at compile time) that cannot be edited is a clumsy way to do constants. If you did want to change that attached item, you would need to compile more source.

In PHP I do not see the value in being able to bind a object to a function (yes that way round); as its hard to unit test. The variable value is bound at compile time, so you can't use this to build dynamic FSM. The last entry attempt to bind a reference not the value, but this is forbidden. This effectively means you have re-introduced global variables again for no benefit. As the object is statically bound, the reference count on the object will never drop, so garbage collection cannot happen. Test script below, what is this for?

<?php
# I make is under AGPL, see reference <http://www.gnu.org/licenses/>

# yeah, bit maths.  This is PHP not ASM.
error_reporting(~1);


# reference
# http://phpocean.com/tutorials/back-end/php-frameworking-routing-autoloading-configuration-part-2/10

function boring($name) {
	echo "I'm boring. $name\n";
}
$shellShock="~ t00l33+";  
# people who try to be clever for no reason often use "l33t sp3@k"

$t = function() use ($shellShock){
	echo "I am desperate not to use objects. ".$shellShock."\n";
};

boring(" ~ a normal dev");
$t();
$shellShock=" side effect";
$t();

class TEST {
	public $TEST;
	protected $hidden;
}

$self=new TEST();
$self->TEST="initial value";

$t2 = function() use ($self) {
	$self->TEST="TEST";
# as expected this crashes the PHP interp
#	$self->hidden="new value";

};

echo "This starts with an ".$self->TEST."\n";
$t2();
echo "Does this pass the ".$self->TEST."?\n";

$t3 = function() use (&$shellShock){
	echo "I am desperate not to use objects. ".$shellShock."\n";
};
# my initial copy had a typo here, and was running the first edition of the function, not this one.
$t3();
$shellShock="references FTW!";
$t3();

# Unless this lets you avoid a PHP bug, I have no idea why this is useful.
# Does anyone have a performance chart for this?  Compile once, 
#   run many is generally better than compile all the time.

PHP 'use' oddity

RSS. Share: Share this resource on your twitter account. Share this resource on your linked-in account. G+

PHP 'use' oddity

RSS. Share: Share this resource on your linked-in account. Share this resource on your twitter account. G+ ­ Follow