PHP Ferrari
PHP Ferrari

Reputation: 15616

Get value from constructor to a function in php class

i have a class like:

class List_PendingVerify extends Rs_List {

 public function __construct( $id ) {
           }

    protected function loadData( ) {
           }
}

Now i how could i get value of $id in loadData function ?

so that i can be able to echo $id.

Thanks.

Upvotes: 1

Views: 477

Answers (1)

Ben James
Ben James

Reputation: 125167

class List_PendingVerify extends Rs_List {
    public function __construct($id) {
        $this->id = $id;
    }

    protected function loadData() {
        echo $this->id;
    }
}

I recommend reading the Classes and Objects documentation. (In particular, the Properties section is relevant here.)

Upvotes: 3

Related Questions