Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add a PHP array key without an assigned value in a class variable?

I am currently plowing my way through IBM's tutorial on CakePHP

At one point I run into this snippet of code:

<?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'
        )
    );
}
?>

When I run it I get the following error-message: "Parse error: syntax error, unexpected ',' in /Applications/MAMP/htdocs/cakephp/app/models/product.php on line 7"

I'm a n00b at PHP so my question is: is it allowed to make an array with keys without assigned values? Has anybody played around with this tut and know what is up?

like image 245
timkl Avatar asked Apr 09 '26 05:04

timkl


1 Answers

Assign the value null instead of leaving anything out. The 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'
            )
        );
    }
?>

This works fine.

like image 181
Vegard Larsen Avatar answered Apr 10 '26 19:04

Vegard Larsen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!