Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

What are the names of the properties of a class that can be used in zephyr?

I'm creating an extension containing the class

namespace ExtABC;

class ClassA
{
    public $A1;

    public function __construct()
    {
    }
}

During compilation I get an error

Syntax error in extabc/classb on line 5

    public $A1;
------------^

Why the simple property name $A1 can not be used in zephyr?

Property name $A1 is not essential for me, I just wanted to use it in my previous post in this forum. This name has caused an error and instead it I used the name of the property $abc )))

Let's look at another example. Let extension ExtABC contains two classes ClassA and ClassB.

namespace ExtABC;

class ClassA
{
    protected $id;
    protected $name;

    public function __construct()
    {
        let $this->id = "";
        let $this->name = "";
    }

    public function __get(var $prop)
    {
        switch ($prop)
        {
            case "ID":
                return $this->id;
            case "Name":
                return $this->name;
        }
    }

    public function __set(var $prop, var $value)
    {
        switch ($prop)
        {
            case "ID":
                let $this->id = $value;
                break;
            case "Name":
                let $this->name = $value;
                break;
        }
    }
}
namespace ExtABC;
use ExtABC\ClassA;

class ClassB
{
    public function __construct()
    {
        var $objectA;
        let $objectA = new \ExtABC\ClassA();
        let $objectA->ID = "objectA";
        let $objectA->Name = "objectA";
    }
}

During compilation I get an error

Syntax error in extabc/classb on line 10

        let $objectA->ID = "objectA";
----------------------^

This already is a very significant error.

So what are the names of class properties and class methods that are acceptable in zephir?



971
Accepted
answer
edited Feb '16

You might have figured this out in the meantime, but as opposed to PHP, you don't need to use '$' to designate variables and keywords like 'this' when writing Zephir code. Remove the $ and try again.

See Basic Syntax

Good luck!