循环访问对象数组时 Netbeans Code Complete 未激活
在我的 Netbeans PHP 项目中,我最近开始将自定义对象填充到数组中以提高性能。我发现它查询数据库并获取一堆对象的速度要快得多一次全部完成,而不是一遍又一遍地查询。
我喜欢这种新方法,除了当我循环数组并尝试访问每个对象时,Netbeans 不知道数组中的项目实际上是对象。尝试以下示例代码,例如:
foreach ($arrAccounts as $objAccount) {
echo ( $objAccount->get_name() . " - " . $objAccount->get_type() );
...
}
当我键入“$objAccount->”时,Netbeans 无法识别它是自定义 Account 类。
In my Netbeans PHP projects, I recently started stuffing custom objects into arrays in order to increase performance. I found its much faster to query the database and get a bunch of objects all at once instead of querying over and over again.
I love the new approach, except when I loop through the array and try to access each of the objects, Netbeans doesn't know that the items in the array are actually objects. Try to following example code, for instance:
foreach ($arrAccounts as $objAccount) {
echo ( $objAccount->get_name() . " - " . $objAccount->get_type() );
...
}
When I type "$objAccount->", Netbeans doesn't recognize that it is a custom Account class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在循环内添加 vdoc 并输入
$objAccount
的类名Shortcut = [vdoc + tab]
inside the loop add vdoc and enter classname of the
$objAccount
Shortcut = [vdoc + tab]
如果您在类名后添加“[]”,另一种方法可以是元素数组的 phpdoc:
我发现这对于代码清晰度更好,因为您指定了一次数组的类型。那么无论您在 foreach() 中分配它还是直接根据键直接访问数组的元素都没有关系。
Another approach can be phpdoc for array of elements if you add "[]" after classname:
I find this better for code clarity because you specify the type of your array once. Then it does not matter if you assign it within foreach() or you directly access elements of the array directly based on keys.