> For the complete documentation index, see [llms.txt](https://learnphp.gitbook.io/learnphp/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnphp.gitbook.io/learnphp/ngan-gon-ve-cach-su-dung-and-full-ok.md).

# Ngắn gọn về cách sử dụng &,!,@ full, parent::\_\_construct() (ok)

### & dùng để thay đổi giá trị biến ở bên ngoài

Ví dụ 1:

Class

```
<?php
class A {
	function foo(&$var) {
		$this->result1 = &$var;
		$this->result2 = $var;
		$var++;
	}
}
$var = 3;
$test = new A();
$test->foo($var);
echo $test->result1; // Result is 4
echo $test->result2; // Result is 3
?>
```

Function&#x20;

```
<?php
function changeString(&$sTest1, $sTest2, $sTest3) {
  $sTest1 = 'changed';
  $sTest2 = 'changed';
  $sTest3 = 'changed';
};
$sOuterTest1 = 'original';
$sOuterTest2 = 'original';
$sOuterTest3 = 'original';
changeString($sOuterTest1, $sOuterTest2, $sOuterTest3);
echo ("sOuterTest1 is $sOuterTest1 <hr/>");
echo ("sOuterTest2 is $sOuterTest2 <hr/>");
echo ("sOuterTest3 is $sOuterTest3 <hr/>");
// sOuterTest1 is changed
// sOuterTest2 is changed
// sOuterTest3 is original
?>
```

### @ dùng để không gây ra cảnh báo

```
<?php
// điều này hoạt động cho bất kỳ biểu thức, không chỉ các chức năng:
$value = @$cache[$key];
// sẽ không đưa ra thông báo nếu chỉ số $ key không tồn tại.
?>
```

! Tạo ra một lỗi cố ý tức là nó ẽ trả về false

```
/* Lỗi tập tin cố ý */
$my_file = !@$cache[$key];
var_export($my_file);
sẽ trả về false
```

### parent::\_\_construct() kế thừa toàn bộ construct bên parent

```
<?php
if (!class_exists('Form')) {
  require_once 'form.php';
}

class AppModel {
  public $form     = null;
  protected $rules = null;
  public function __construct() {
    $this->form = new Form();
    $this->form->setRules($this->rules);
  }
}
?>
```

```
<?php  
if(!class_exists("AppModel")) {
  require_one "appmodel.php";
}
class User extends AppModel {
    protected $rules = array(
      "text"     => array(
      "form"     => array(
        "type" => "text",
      ),
      "notEmpty" => array(
        "rule"    => "notEmpty",
        "message" => 'MSG_ERR_NOTEMPTY',
      ),
    ),
    "email"    => array(
      "form"     => array(
        "type" => "email",
      ),
      "notEmpty" => array(
        "rule"    => "notEmpty",
        "message" => 'MSG_ERR_NOTEMPTY',
      ),
      "isEmail"  => array(
        "rule"    => "email",
        "message" => 'MSG_ERR_EMAIL',
      ),
    ),
    "password" => array(
      "form"     => array(
        "type" => "password",
      ),
      "notEmpty" => array(
        "rule"    => "notEmpty",
        "message" => 'MSG_ERR_NOTEMPTY',
      ),
    ),
    "fullname" => array(
      "form"     => array(
        "type" => "text",
      ),
      "notEmpty" => array(
        "rule"    => "notEmpty",
        "message" => 'MSG_ERR_NOTEMPTY',
      ),
    ),
    "address"  => array(
      "form"     => array(
        "type" => "textarea",
      ),
      "notEmpty" => array(
        "rule"    => "notEmpty",
        "message" => 'MSG_ERR_NOTEMPTY',
      ),
    ),
  );
  public function __construct() {
    parent::__construct();
  }
}
?>
```
