getter and setter for private and protected property

/ Published in: PHP
Save to your folder(s)

To access a protected or private property, you need to create getter and setter
methods inside the class file.

Copy this code and paste it in your HTML
  1. // methods defined here
  2. public function getProductType()
  3. {
  4. return $this->_type;
  5. }
  6. public function setProductType($type)
  7. {
  8. $this->_type = $type;
  9. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.