Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array helper for properties (by trait) #7

Open
Sett opened this issue Apr 14, 2014 · 2 comments
Open

Array helper for properties (by trait) #7

Sett opened this issue Apr 14, 2014 · 2 comments

Comments

@Sett
Copy link

Sett commented Apr 14, 2014

Sometimes (more often, than wanted) there are array-properties in a class. It would be so cool, to get helpers for working with them.

I can show you the realization of this:

class My
{
    use Ohanzee\Helper\Trait\Arr;

    public $data = [
        'foo' => ['bar' => 'foobar']
    ];

    // somewhere in a methods code
    ...
    // Getting $this->data['foo']['bar']
    $this->{'foo.bar'}; 
    ...
}

What do you think about it?

@shadowhand
Copy link
Contributor

I'm not so sure about the syntax $this->{'foo.bar'} but I generally like the concept. Would be really great if there was both WritableArr and ReadableArr, where ReadableArr would let you read data out, but not modify values.

@Sett
Copy link
Author

Sett commented Apr 15, 2014

Syntax will work wright, if you about it. Due to readbale/writable, it can be in such way:

//readable by using __get
$this->$key; // or $this->{'some:deep:key'}

// writable by using __call
$this->$key($value); // or $this->{'some:deep:key'}($value);

I have one more question: to the concept of the Ohanzee project, can I use already created classes, or for each "feature" should be a separated class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants