# 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();
  }
}
?>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learnphp.gitbook.io/learnphp/ngan-gon-ve-cach-su-dung-and-full-ok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
