0

I have this example on php

class My_Example_List_Table extends WP_List_Table {

    var $example_data = array(
            array( 'ID' => 1,'fullname' => 'Quarter Share', 'email' => 'Nathan Lowell', 
                   'driver' => '978-0982514542' , 'medic' => '0000'),
            array( 'ID' => 2, 'fullname' => '7th Son: Descent','email' => 'J. C. Hutchins',
                   'driver' => '0312384378' , 'medic' => '0000'),
            array( 'ID' => 3, 'fullname' => 'Shadowmagic', 'email' => 'John Lenahan',
                   'driver' => '978-1905548927' , 'medic' => '0000'),
            array( 'ID' => 4, 'fullname' => 'The Crown Conspiracy', 'email' => 'Michael J. Sullivan',
                   'driver' => '978-0979621130' , 'medic' => '0000'),
            array( 'ID' => 5, 'fullname'     => 'Max Quick: The Pocket and the Pendant', 'email'    => 'Mark Jeffrey',
                   'driver' => '978-0061988929' , 'medic' => '0000'),
            array('ID' => 6, 'fullname' => 'Jack Wakes Up: A Novel', 'email' => 'Seth Harwood',
                  'driver' => '978-0307454355' , 'medic' => '0000')
        );

what am I trying to do is populate the array from the database so I did this:

function getContactAttachmentList(){
    $users = get_users( 'role=subscriber' );

    $data = array();
    foreach ($users as $key) {

        $data[] = array( 
            'ID' => $key->ID,
            'fullname' => get_user_meta( $key->ID, 'first_name', true ).' '.get_user_meta( $key->ID, 'last_name', true ), 
            'email' => esc_html( $key->user_email ), 
            'driver' => get_user_meta( $key->ID, 'drivers', true ), 
            'medic' => get_user_meta( $key->ID, 'medics', true )
            );
    }

    return $data;
}

so I have this code now:

class My_Example_List_Table extends WP_List_Table {

        var $example_data = getContactAttachmentList();

the problem is I got this error in that line:

Parse error: syntax error, unexpected '(', expecting ',' or ';'

does anyone have an idea about this? thanks in advance

gadss
  • 21,687
  • 41
  • 104
  • 154
  • possible duplicate [`Call a function while setting class properties`](http://stackoverflow.com/q/5475228/689579) – Sean Apr 02 '15 at 01:03
  • i don't think so.. I am concerning in the array I guess – gadss Apr 02 '15 at 01:04
  • 1
    Try setting `var $example_data` using `public function __construct() { $this->example_data = = getContactAttachmentList(); }` – Sean Apr 02 '15 at 01:06
  • also, from the php docs - [`This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.`](http://php.net/manual/en/language.oop5.properties.php) – Sean Apr 02 '15 at 01:08

0 Answers0