In this post I want to show some resource and tips to improve, validate and document your PHP code, and also if you want how to be compatible when PHP 6 when will be available.
PHPLint
A validator and a documentator of PHP programs. The programmer
can add to the source the PHPLint meta-code, that enhance the syntax of
the PHP language toward the paradigm of a strong-typed language and safe
programming.
Enablig the Enterprise with Zend
Zend Platform is the only application server for PHP that supports the performance, management, integration, and enterprise scalability requirements of organizations using PHP for their business-critical applications. By providing capabilities that streamline development and deployment, Zend Platform improves the user experience, application responsiveness, integration to your existing infrastructure, and increases application reliability and scalability.
Java technologies:
â— PHP has an extension to interact with Java.
â— This extension gives access to all Java APIs (calls are only by values).
â— Another bridge is hosted at SF.net
â— Java APIs related to distributed programming are RMI and JMS.
â— The protocol is binary thus giving performance advantage.
RMI - architecture:
Things to know when working with Java
â— Classes are instantiated with Java class:
$string = new Java('java.lang.String');
â—When the class has no public constructor the PHP variable is an object of class java.lang.Class.
â— Calling static method is no different than calling normal methods.
â— Java exceptions are PHP errors. A E_WARNING will be generated on exception.
â— java_last_exception_get() tell you if there was an exception. Use java_last_exception_clear() to clear it.
â—One can define his own error handler.
Accessing remote service over RMI:
<?php
function gettime() {
return array_sum(explode(' ', microtime()));
}
function err_handler($errno, $errstr, $errfile, $errline) {
if ($ex = java_last_exception_get()) echo $ex->toString()."\n";
java_last_exception_clear();
}
set_error_handler("err_handler");
$class = new Java("java.rmi.Naming");
$calculator = $class->lookup("rmi://localhost/CalculatorService");
var_dump($calculator->sub(14,3));
$i = 0;
$start = gettime();
while ($i++ < 500) $calculator-> sub($i, 20);
$end = gettime();
printf("Finished %d calls in %2.5f\n", $i1, $end-$start);
//now let's generate an exception
var_dump($calculator->fakeMethod());
echo "\nOK\n";
?>
Tips that improve your PHP code:
â— echo is faster than print
◠$row[’id’] is 7 times faster than $row[id]
â— Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
â— Close your database connections when you're done with them
â— Error suppression with @ is very slow.
Also if you want to be compatible with PHP6:
â— Do not use register_globals. In PHP6 will not exists any option to access it.You'll can use this vatiable:
$_GET['input'];
$_POST['input'];
$_REQUEST['input'];
â— Don't use magic_quotes
â— use preg instead ereg.
â— Don't initiate objects with the reference operator. If you're initiating objects using the reference operator, you should stop now. It will generate an E_STRICT error.
$a = & new object(); // No
$a = new object(); // Yes