undefined
undefined

Gọi phương thức của class


Gọi phương thức của class cũng giống như gọi thuộc tính của class, cú pháp gọi phương thức của class như ví dụ dưới đây:

<?php
class myclass
 {
  var $attribute;
  function get_attribute()
  {
   return $this->attribute;
  }
  function set_attribute($new_value)
  {
   $this->attribute=$new_value;
  }
  function abc($x,$y)
  {
   return $x+$y;
  }
 }
?>
<html>
<head>
  <title>Classes and Object</title>
</head>
<body>
<?php
 $a=new myclass();
 $a->set_attribute("Protect Attribute");
 echo "a:".($a->get_attribute());
 echo "<br>";
 $total=$a->abc(12,9);
 echo "total $total";
?>
</body>
</html>


0 nhận xét to "Gọi phương thức của class"

Đăng nhận xét