Académique Documents
Professionnel Documents
Culture Documents
3
Stefan Priebsch
July 31st 2009
namespace my\Application\Models;
use Framework\Model\ModelBase as Model;
class BaseClass
{
static protected $foo = 'foo';
var_dump(BaseClass::getFoo());
var_dump(SubClass::getFoo());
class BaseClass
{
static protected $foo = 'foo';
var_dump(SubClass::getFoo());
class SomeClass
{
static public function foo()
{
var_dump('foo method');
}
}
$classname = 'SomeClass';
$classname::foo();
src/:
... any files ...
stub.php:
Phar::mapPhar('alias.phar');
...
__HALT_COMPILER();
create_phar.php:
$phar = new Phar('executable.phar');
$phar->buildFromDirectory('./src');
$phar->setStub(
file_get_contents('./stub.php'));
Migration Problems
Environment
Old Extensions
Compile-time errors
Name Conflicts
More strictness
Runtime errors
New error messages (E_DEPRECATED)
Logic errors
Altered behaviour
Altered function behaviour
var_dump(strrpos($haystack, $needle));
Altered function behaviour
var_dump(strrpos($haystack, $needle));
PHP 4: int(9)
Altered function behaviour
var_dump(strrpos($haystack, $needle));
PHP 4: int(9)
PHP 5: int(3)
Solution: Create a wrapper
function strrpos_wrapper($haystack,
$needle,
$offset = 0)
{
return strrpos($haystack,
substr($needle, 0, 1),
$offset);
}
More Strictness
Strict standards:
Static function should not be abstract
More Strictness
Fatal error:
Abstract function cannot be declared private
Useful Tools
Lint: php -l
Validators (HTML, XML, CSS, JS)
PHPUnit
http://www.phpunit.de
Selenium
http://seleniumhq.org
xdebug
http://www.xdebug.org
xdebug Function Trace
Mocking
include_once './library/function.php';
library/function.php:
function get_random_value()
{
return rand(1, 10);
}
Mocking
mock_library/function.php:
function get_random_value()
{
static $i = 0;
static $random_values =
array(1, 2, 3, 4, 5);
return $random_values[$i++];
}
Mocking
include_once './mock_library/function.php';
Fix errors/warnings/notices
Normalize the PHP configuration
Set up two test systems, old and new
Do A/B testing
Compare the results
Fix the problems
Switch the production system
FutureProof PHP Configuration
ze1.compatibility_mode=Off
allow_call_time_pass_reference=Off
register_globals=Off
magic_quotes_*=Off
register_long_arrays=Off
http://www.phparch.com/books/index
Code Works '09 Workshops
http://cw.mtacon.com
Thank You.
■ http://thePHP.cc
■ http://www.priebsch.de
■ http://www.slideshare.net/spriebsch
■ http://twitter.com/spriebsch
■ stefan@thePHP.cc, IRC: spriebsch