|
|
In the section
Nombre de visites : 267 Mise en ligne : 10/2006 Dernière modif : 04/2008 PHP wish listHere are wishes I note while developing in php5.
So here are features I would use if they were existing. When I have internet at home, I’ll search on php.net wher to post that.
Classes and Objects
public myClass{
static{
// static initializations here
}
}
To replace this feature, I do : myClass::init();
myClass{
private $initOK = false;
public static init(){
$initOK = true;
}
public function function1(){
if(!self::$initOK) self::init();
}
}
Particular functions
The PHP manualThere is a really useful page : the function index, listing all the functions. In the index page of the php manual, this link is at the bottom of page, in the "Appendices" section. It took me years before realizing that this page exists ! A better place for this link would be at the beginning of "Function Reference" paragraph.
A standard PHP code documentrorComing from java, a standard and uniform way to document the code is badly missing in PHP.
PHP syntax
interface TheInterface{
const THE_CONSTANT = 3;
}
class TheClass implements TheInterface{
public static function toto(){
echo TheInterface::THE_CONSTANT; // php actual way
echo THE_CONSTANT; // not valid in php - java syntax
}
}
TheClass::toto();
This syntax is sometimes heavy : I’m storing constants in interfaces, and want to name them for ex : TimeConstants, SpaceConstants, AstronomyConstants...
/** Array containing the codes of gazeous planets */
$gazeousPlanets = array(
SolarSystemConstants::JUPITER,
SolarSystemConstants::SATURN,
SolarSystemConstants::URANUS,
SolarSystemConstants::NEPTUNE
);
Php syntax is heavier than java’s for object manipulation :
I personally find the "->" syntax cumbersome to type, and this leads me sometimes to stupidities (for example, design a class only with static functions, just because typing "::" is more convenient than typing "->"). Would it be possible to adapt the php interpreter so that it also undersands the java and python syntax ?
$object = new myClass(); $name = $object.getField(’name’);instead of : $name = $object->getField(’name’); Maybe a patch : have a stack of syntaxes to try, recognize the current syntax, translate it to the usual php syntax, and pass it to the usual php interpreter. A feature like that would maybe complicate life to php developers (dealing with several syntaxes), but the code would look nicer.
Miscellaneous
|