Page 1 of 1

classes and array attributes

Posted: Mon Jul 04, 2005 9:09 am
by stef31
Hi,

Newbie question I guess. I'd like to declare an array as an attribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color]urse wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this-&gt;f1($my_array) ;
  }
}

?&gt;
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color]gs don't disable BBCode... that's just silly  [/color]bute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color] warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

&lt;?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this-&gt;f1($my_array) ;
  }
}

?&gt;
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an an attribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will justion I guess. I'd like to declare an array as an attribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color]tribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

&lt;?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this-&gt;f1($my_array) ;
  }
}

?&gt;
Calling f2 will just say that array_rand expects an a to declare an array as an attribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color]tion I guess. I'd like to declare an array as an attribute of a class. Everytime I try to use the declared array, I have a warning saying the attribute is not an array, and the result is of course wrong.

For example

Code: Select all

&lt;?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this-&gt;f1($my_array) ;
  }
}

?&gt;
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color:1a
<?php
class ACLass
{
  var $my_array = array() ;

  function f1($p)
  {
    return array_rand($p) ;
  }

  function f2()
  {
    return $this->f1($my_array) ;
  }
}

?>
Calling f2 will just say that array_rand expects an array as first parameter - which I know, and $my_array IS an array...

What's wrong ?

Thanks,

d11wtq | If you're using

Code: Select all

tags don't disable BBCode... that's just silly  [/color]

Posted: Mon Jul 04, 2005 9:13 am
by Todd_Z

Code: Select all

<?php
class ACLass {
  var $my_array;
  function ACLass ( ) { $this->$my_array = array(); }
  function f1( $p ) { return array_rand( $p ); }
  function f2() { return $this->f1($my_array); }
}
?>
It may have been that you need a constructor to intitiate a variable into an array.rn $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array. function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array.function f1( $p ) { return array_rand( $p ); }
function f2() { return $this-&amparray;
function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array.
<?php
class ACLass {
var $my_array;
function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array.;
function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this-&gt;f1($my_array); }
}
?&gass ACLass {
var $my_array;
function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array.
<?php
class ACLass {
var $my_array;
function ACLass ( ) { $this->$my_array = array(); }
function f1( $p ) { return array_rand( $p ); }
function f2() { return $this->f1($my_array); }
}
?>


It may have been that you need a constructor to intitiate a variable into an array.

Posted: Mon Jul 04, 2005 10:59 am
by timvw
Almost there... ;)

Code: Select all

<?php
class ACLass 
{
  var $my_array;

  function f1($p) 
  { 
    return array_rand($p); 
  }

  function f2() 
  { 
    return $this->f1($this->my_array); 
  }
}
?>
;f1($this->my_array);
}
}
?>
{
var $my_array;

function f1($p)
{
return array_rand($p);
}

function f2()
{
return $this->f1($this->my_array);
}
}
?>and($p);
}

function f2()
{
return $this->f1($this-&amACLass
{
var $my_array;

function f1($p)
{
return array_rand($p);
}

function f2()
{
return $this-&gt;f1($this->my_array);
}
}
?>

Code: Select all

<?php
class ACLass 
{
  var $my_array;

  function f1($p) 
  { 
    return array_rand($p); 
  }

  function f2() 
  { 
    return $this->f1($this->my_array); 
  }
}
?>
s
{
var $my_array;

function f1($p)
{
return array_rand($p);
}

function f2()
{
return $this-&gt;f1($this-&gt;my_array);
}
}
?&<?php
class ACLass
{
var $my_array;

function f1($p)
{
return array_rand($p);
}

function f2()
{
return $this->f1($this->my_array);
}
}
?>