Re: Array_keys problem

From: Date: Sun, 04 Apr 2004 08:26:01 +0000
Subject: Re: Array_keys problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182271@lists.php.net to get a copy of this message
Robin 'Sparky' Kopetzky wrote:
Good afternoon. I'm building a class and am having a bunch of trouble with the PHP array_keys function. I keep getting these errors: Warning: First argument to array_keys() should be an array in D:\Htf.php on line 33 Warning: Wrong datatype for second argument in call to in_array in D:\Htf.php on line 35 $this->ma_arguments IS an array, so why is the error popping up? I did check syntax but am buffaloe'd by this one. Just so no one gets confused, I use a form of Hungarian (p=parameter, m=module, a=array, s=string)
Since PHP doesn't have strict typing, you can't be sure what it is. I've edited your code a bit.
      /**
       * @var assoc array of passed arguments
       */
      //var $ma_arguments;
        var $ma_arguments = array();
      /**
       * Constructor
       */
      function bmc_html_tag_functions()
      {
      	//$this->init();
      }
function init() { $this->ma_arguments = array();
}
      /**
       * Checks if the given key or index exists in the array (PHP < 4.1.0)
       *
       * @param $ps_key    Key to check against
       * @param $pa_search Array of elements
       * @return true if key is in array
       * @access private
       */
      function key_exists($ps_key)
      {
            if (!is_array($this->ma_arguments))
            {
                echo '$this->ma_arguments is not an array';
                echo '<pre>'; var_dump($this->ma_arguments); echo '</pre>';
if ( in_array($ps_key, array_keys($this->ma_arguments)) ) { return true; } else { return false; } }
Try that.

« previous php.general (#182271) next »