May
28
2009
Working on a PHP project currently, I found myself doing the same thing again and again. Whenever I needed some test output of some PHP code, I opened a new PHP file in my code editor, added some lines of code, thinking of a filename and save it. Then I open up the browser and tried to remember the filename again to run the script via my localhost.
This became boring after a while so I searched the web for a solution to execute PHP code dynamically on the fly. Unfortunately, I did not find any good solution that’s why I started this little project. I named it Dynamic PHP Executor.
What is it about ?
It’s a little PHP page that allows you to enter PHP code and execute it directly on the fly. This way you can test little PHP snippets without saving them to disc.
The Dynamic PHP Executor comes in a single file, ie. it does need not any additional include files.
A quick note to CSS/Javascript/HTML designers
In general, I know that this is not a good habbit to put CSS styles, javascript code et cetera into a single file. However in this case, it helps to keep this project small and compact.
How does it work ?
The core functionality consists of one PHP line only actually
eval(stripslashes($_POST['phpCode']));
So, the request data contains the PHP code. This is evaluated. The function stripslahes is required since all quotations are escaped when posted. Here is screenshot of how it looks in action.

Be careful though!
Only use this script in a secure environment. The user of the tool can run any PHP code he wants on your machine. Please keep this in mind and read the disclaimer inside the file.
Try it
Download the source, read the disclaimer and comments inside the file. Then simply run it through a PHP enabled web server.
Name: Dynamic Php Executor
Size: 2.58 KB
Hits: 88
no comments | tags: Dynamic PHP Executor, execute php on the fly | posted in PHP
May
24
2009
The usage of arrays in actionscript is nearly the same like the in other programming languages. However, there are some fine technical intricacies to point out.
First of all, the elements of an array in actionscript can be of different types. That means, you can put various types of elements in the same array. Following small example illustrates that:
public function Main()
{
var arr:Array = [ 1, "Two", { id:3 } ];
for (var i:uint = 0; i < arr.length; i++)
{
trace(typeof(arr[i]));
}
// Will result in the following output:
// number
// string
// object
}
Above’s code extract creates an array called arr which holds three elements. All elements are of a different type.The element at index 0 is of type Number, index 1 is of type String and finally index 2 is an object.
Another special thing about arrays in actionscript is that the memory of arrays are allocated automatically. That means, that you do not have to care about reserving memory if you want to add elements e.g. So theroretically each array has an unlimited amount of elements. Accessing an element which actually has never been created does not resolve in an error like in other programming languages (Array index out of bounce). Refer to the following example:
// Create an array which holds 2 elements
var arr:Array = new Array(2);
// Now try to access the third element
// This does not result in an error like in
// other programming languages
trace(arr[2]);
Although above’s code creates an array which should hold only 2 elements, we still can try to access the third element without retrieving an error. The third element is simply undefined (i.e. equals null). Keeping this in mind, the length property returns actually the index of the last used element instead of the real amount of elements of the array. The final piece of code demonstrates the return values of length:
var arr:Array = new Array();
trace(arr.length);
arr[0] = 1;
trace(arr.length);
arr[100] = 2;
trace(arr.length);
// This code outputs:
// 0
// 1
// 101
no comments | tags: ActionScript, Array, AS3.0 TutBits | posted in ActionScript
May
21
2009
In many programming lanugages there is a keyword for something which is empty, not set or an invalid pointer. So, there is null in Java, nil in Ruby, None in Python and finally NULL in PHP. Although they somehow appear to describe the same thing - be aware of their differences when switching from one programming language to another.
For example, in C++ NULL is defined as the number zero :
In PHP however, NULL is a datatype. The only possible value of NULL is NULL. That means if you assign NULL to a variable you unset the variable while assigning to it the value and type NULL - and not zero. The trapfall however is, that you need to be careful if you are checking a variable for a NULL value/type.
$var = NULL;
if ( NULL == $var ) echo "Var is NULL";
// outputs Var is NULL
The if-clause is true in this case - but this check is error-prone. Look at the following check:
$var = 0;
if ( NULL == $var ) echo "Var is NULL";
// outputs Var is NULL
This if-clause is true as well, since PHP just checks if the value of NULL and $var is equal. The converted integer value of NULL is 0
echo (int)NULL;
// outputs 0
Therefore the if clause is true. To really test if the values are equal and the type is identical you need to use the “===”-comparison operator of PHP.
Alternatively, you can use the php function is_null() to determine if a variable is of type NULL.
no comments | tags: NULL in PHP, PHP | posted in PHP
May
15
2009
When you create a variable in ActionScript you normally add its type, e.g.
Whenever you assign to that variable a value of another type the compiler will throw type mismatch errors.
// This will result in a type mismatch error
age = -10;
Actionscript provides untyped variables. You can set them explicitly with the datatype “*“, e.g.:
var anything:*;
anything = 10;
anything = "Test";
anything = new Array();
Above code will not throw any type mismatch errors, because the variable is declared as an untyped variable. So you can assign values of any kind to it.
From my personal point of view however, you should avoid using untyped variables whenever you can.
no comments | tags: ActionScript, AS3.0 TutBits, untyped variables | posted in ActionScript
May
8
2009
Nested functions are functions which are defined inside a method or in other function. They are only accessible in the method/function in which they are defined. Once there is a definition of a function inside a method it does not matter if you call that nested function before its definition or after it. It works in both cases.
Here is a short example of a nested function.
private function doCalculation():void
{
for (var i:uint; i < 10; i++)
{
// Do some serious calculation
nestedLog("Calculation " + i + " done");
}
// Nested function
function nestedLog(logTxt:String):void
{
trace(logTxt);
}
}
The function defined in line 10 is only accessible in the scope of the method doCalculation(). Therefore, it is illegal to add any control access modifiers (public, private, protected) to the function.
Nested functions may be used to store some method-specific subroutines.
no comments | tags: ActionScript, AS3.0 TutBits, nested functions | posted in ActionScript, PHP