Q:

How to set value to variable of class and display it?

In my project, I have defined a Test class.
Only __construct function in this class, Here is code of Test class:
<?php
namespace model;
public  class Test  {
private $db;
protected $fields;
public $variables;

public function __construct($data = array()) {
    if ($this->fields && $data) {
        foreach ($data as $k => $d) {
            if (!in_array($k, $this->fields)) {
                unset($data[$k]);
            }
        }
     }
    $this->variables  = $data;
}

}

Now I want to use this class, Here is my html code:
<body style="height:100%" >
<?php 
include "o1ws1v/class/model/Test.php";//include class file
$test_model = new \model\Test();

$test_model->xie="zuo";
echo    $test_model->xie;
?>
</body>

But unlucky, It works fail. Nothing is showed in console.
I have tested:
var_dump($test_model);

It also did nothing . 
I want to assign  value to a variable of Test class and display it.
Who can help me?

A:

With your code as it is you'll get an error 

PHP Parse error: syntax error, unexpected 'public' (T_PUBLIC),
  expecting end of file in ...

Remove the public keyword from your Test class:
<?php

namespace model;

class Test  {
    private $db;
    protected $fields;
    public $variables;

    public function __construct($data = array()) {
        if ($this->fields && $data) {
            foreach ($data as $k => $d) {
                if (!in_array($k, $this->fields)) {
                    unset($data[$k]);
                }
            }
        }
        $this->variables  = $data;
    }

}

