访问php中的受保护变量

时间:2018-04-12 08:21:31

标签: php

我在php中创建了受保护的变量,并希望在同一个类中的php函数中使用。我打印了$program_owner_id

  

未定义的变量:project_owner_id

<?php
class userController extends Controller
{
  protected $program_owner_id = array (); //protected variable

  public function mappingUserToRequest() {
    print_r($program_owner_id)  //Expected to use here
  }
}
?>

1 个答案:

答案 0 :(得分:3)

可以通过$this访问类属性:

var_dump($this->program_owner_id);

别忘了分号!

相关问题