Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ErrorException in Obsever
  • Hello,

    I try to writ my own Observer which reads the actual User-ID and stores this with each object into the database.

    I receive an error:
    ErrorException [ Parsing Error ]: syntax error, unexpected '(', expecting ',' or ';'


    PKGPATH/orm/classes/observer/createdby.php @ line 25
    and I have no idea why?!

    Here is my code:

    namespace Orm;

    class Observer_CreatedBy extends Observer
    {
    /**
    * @var string property to set the creation by on
    */
    public static $property = 'created_by';

    /**
    * @var string current_user from Warden
    */
    public static $current_user = \Warden::current_user()->id;

    protected $_current_user;
    protected $_property;

    public function __construct($class)
    {
    $props = $class::observers(get_class($this));
    $this->_current_user = isset($props['current_user']) ? $props['current_user'] : static::$current_user;
    $this->_property = isset($props['property']) ? $props['property'] : static::$property;
    }

    public function before_insert(Model $obj)
    {
    $obj->{$this->_property} = $this->_current_user;
    }
    }

    Thanks for our help.
    Kay
  • HarroHarro
    Accepted Answer
    When defining class properties, you can only assign scalar values. So no method or function calls, no object access, no variables, etc.

    This is not supported by PHP:
    public static $current_user = \Warden::current_user()->id;

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion