php是非强类型语言,所以如果编写字符错误,只有运行期才能提示. 而用 IDE 就方便很多:
eclipse for php 很方便编辑php, 尤其是自动代码提示,帮助我们减少输入变量的错误但是, 如果一个变量,想强制转化为类型,似乎是不行的, 经过摸索,我发现这样一个技巧:
<?phpclass Person
{
var $name;
var $sex;
var $age;
static function Type($obj){
return true ? $obj : new Person();
}
}
$p1= new Person("张三", "男", 20);$p2 = Person::Type($p1);
$p1->age = 50;echo $p2->age;?>这样就能在敲入 $p2->的时候 出现变量name, age, sex的代码提示了.觉得好的话就顶一下吧 :)
eclipse for php 很方便编辑php, 尤其是自动代码提示,帮助我们减少输入变量的错误但是, 如果一个变量,想强制转化为类型,似乎是不行的, 经过摸索,我发现这样一个技巧:
<?phpclass Person
{
var $name;
var $sex;
var $age;
static function Type($obj){
return true ? $obj : new Person();
}
}
$p1= new Person("张三", "男", 20);$p2 = Person::Type($p1);
$p1->age = 50;echo $p2->age;?>这样就能在敲入 $p2->的时候 出现变量name, age, sex的代码提示了.觉得好的话就顶一下吧 :)
class Person
{
var $name;
var $sex;
var $age;
var $car;
static function Type($obj){
return true ? $obj : new Person();
}
function __autoload(){
$this->car = Car::Type(null); //一定要 this起头
}
}class Car
{
var $name;
static function Type($obj){
return true ? $obj : new Car();
}
}$p1= new Person("张三", "男", 20);
$p2 = Person::Type($p1);
$p1->age = 50;echo $p2->age; //自动提示echo $p2->car->name; //自动提示
class TypeDef {
var $id;
var $name;
var $desc;
static function TO_TypeDef($obj){
return $obj;
return new TypeDef();
}
}class Style {
var $id;
var $name;
var $desc;
var $type_id;
static function TO_Style($obj){
return $obj;
return new Style();
}
}这样IDE就能自动敏感提示了. 其实最后一句 new ... 肯定是不执行的.
* @var $p2 Person
*/
$p2 = $p1;
this.id = 0;
this.name = "";
this.desc = "";
this.type_id = 0;
}function StyleOf(value) {
return value;
return new Style();
}
//
$.each(data.styleli, function(key, value) {
var style = StyleOf(value);
style.desc //自动代码提示,不过只出现在 spket js 插件中
楼上的大侠有什么好的类似工具for js 推荐么?
还有什么好方法么?例如
2到3层的代码自动提示, 似乎
/**
* @var $p2 Person
*/
不好用,
我的意思是:
$p2->car->wheel->price //car后面就没有自动提示了.