2008-10-03 39 views
1

我目前春耕我的方式,通过IBM's tutorial on CakePHP我可以在类变量中添加没有赋值的PHP数组键吗?

有一次,我碰到这个代码片段:

<?php 
class Dealer extends AppModel { 
    var $name = 'Dealer'; 
    var $hasMany = array (
     'Product' => array(
      'className' => 'Product', 
      'conditions'=>, // is this allowed? 
      'order'=>, // same thing here 
      'foreignKey'=>'dealer_id' 
     ) 
    ); 
} 
?> 

当我运行它,我收到以下错误消息:“解析错误:语法错误,在第7行中的/Applications/MAMP/htdocs/cakephp/app/models/product.php中出现意外的','

我是PHP的n00b,所以我的问题是:是否允许创建一个数组没有赋值的键?有没有人玩过这个啧啧,知道什么是?

回答

5

将值赋值为null,而不是留下任何东西。该manual says

isset() will return FALSE if testing a variable that has been set to NULL

<?php 
class Dealer extends AppModel 
{ 
var $name = 'Dealer'; 
var $hasMany = array ('Product' => array(
'className' => 'Product', 
'conditions'=> null, 
'order'=> null, 
'foreignKey'=>'dealer_id') 
); 
} 
?> 

这工作得很好。

3

它是合法的,但据我所知,你必须明确地说,这是通过分配空给它“空”,

$hasMany = array ('Product' => array(
'className' => 'Product', 
'conditions'=> null, // is this allowed? 
'order'=> null, // same thing here 
'foreignKey'=>'dealer_id')); 

你给的例子听起来非常错误的,可能不应该工作,因为它不是。

相关问题