We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Property names in Phalcon

It says in the documentation: "Underscores in property names can be problematic when using getters and setters. ... As much of the system expects camel case, and underscores are commonly removed, it is recommended to name your properties in the manner shown throughout the documentation. "

And then we see that Invo is using underscores, as in: public $created_at;

and Vökuró uses camelCase as in: public $createdAt;

What is the correct approach? CamelCase?

I'm using getters and setters for my model classes and have private properties in underscore style, I haven't had a problem with that since Phalcon 2.0.x.

You could also play with the columnMap definition.

class Language extends BaseModel
{
    public function getSource() {
        return 'language';
    }

    public function columnMap() {
        return [
            'id' => 'id',
            'code' => 'code',
            'name' => 'name',
            'native_name' => 'native_name',
            'is_enabled' => 'is_enabled',
        ];
    }

    /** @var int */
    protected $id;
    /**
     * @param int $id
     * @return $this
     */
    public function setId($id) {
        $this->id = $id;
        return $this;
    }
    /**
     * @return int
     */
    public function getId() {
        return $this->id;
    }

    /** @var string */
    protected $code;
    /**
     * @param string $code
     * @return $this
     */
    public function setCode($code) {
        $this->code = $code;
        return $this;
    }
    /**
     * @return string
     */
    public function getCode() {
        return $this->code;
    }

    /** @var string */
    protected $name;
    /**
     * @param string $name
     * @return $this
     */
    public function setName($name) {
        $this->name = $name;
        return $this;
    }
    /**
     * @return string
     */
    public function getName() {
        return $this->name;
    }

    /** @var string */
    protected $native_name;
    /**
     * @param string $native_name
     * @return $this
     */
    public function setNativeName($native_name) {
        $this->native_name = $native_name;
        return $this;
    }
    /**
     * @return string
     */
    public function getNativeName() {
        return $this->native_name;
    }

    /** @var bool */
    protected $is_enabled;
    /**
     * @param bool $is_enabled
     * @return $this
     */
    public function setIsEnabled($is_enabled) {
        $this->is_enabled = $is_enabled;
        return $this;
    }
    /**
     * @return bool
     */
    public function getIsEnabled() {
        return $this->is_enabled;
    }
    /**
     * @return bool
     */
    public function isEnabled() {
        return $this->is_enabled;
    }
}