1

it seems I missed something important about arrays in PHP.

What's wrong with this:

var $condition = array('Status.name = ' => 'PUBLISHED');
var $paginate = array('conditions' => $condition );

this works just fine:

var $paginate = array('conditions' => array('Status.name = ' => 'PUBLISHED' ));
2
  • Do you get an error, or what exactly doesn't work? Commented Dec 23, 2009 at 10:57
  • You forgot to describe the context of the code; it can be easily guessed from what you write, but it still a guess. It would have been better if you would have explicitly said if you are reporting a class code; differently, you will get many answers telling you the code is not correct. Commented Dec 23, 2009 at 11:11

4 Answers 4

3

Why the var keyword? Normally you wouldn't need this - unless these are fields on an object?. If so, you will need to reference them using $this. One of the following examples should work for you:

$condition = array('Status.name = ' => 'PUBLISHED');
$paginate = array('conditions' => $condition );

or

var $condition = array('Status.name = ' => 'PUBLISHED');
var $paginate = array('conditions' => $this->condition );

Without seeing more of the code, it is hard for me to say with certainty which one applies to you and/or if this will solve your problem. Hopefully it's pointed you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

3

The var part suggests me that you are defining a class. In that case, you cannot initialize an object variable with the content of another one; you can only initialize them with constants (which includes array).

<?php
  class test {
    var $test1 = array('test_11' => 10);
    var $test2 = array('test21' => $test1); // Error
  }
?>

If you need to initialize the content of a variable with the content of another one, then use the constructor.

<?php
  class test {
    function test() {
      $this->test1 = array('test_11' => 10);
      $this->test2 = array('test21' => $this->test1);
    }
  }
?>

Comments

1

The var keyword is for declaring the class member variable and not for non-class variables.
The var keyword is supported in PHP5, albeit deprecated.

But for the var keyword, everything works as expected and we see the following when we dump the paginate array:

array(1) {
  ["conditions"]=>
  array(1) {
    ["Status.name = "]=>
    string(9) "PUBLISHED"
  }
}

Comments

0

For me, both do not work. However, when i remove the var keyword from variables, both work perfectly well. Var keyword was used in php4.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.