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

Getters #12

Closed
gerbenjacobs opened this issue Dec 4, 2015 · 2 comments
Closed

Getters #12

gerbenjacobs opened this issue Dec 4, 2015 · 2 comments
Labels
Milestone

Comments

@gerbenjacobs
Copy link
Owner

Question:

Lately in Laravel I have seen a lot of people use the variable name as getter, without the Java-esque way of camelcasing.

What should we use in v2?

// Group entity

// #1
function getDescription() {}

// #2
function description() {}

// #3 - no getter at all
public $description;

// #4 magic __get
function __get() {
  // if get$name() exists use that
  // else if theres a property use that
  // else error; not found
}

This would translate in output as follows:

// Output

// #1
echo 'Room: ' . $room->getDescription() . ' - Visit now!';

// #2
echo 'Room: ' . $room->description() . ' - Visit now!';

// #3 & #4
echo 'Room: ' . $room->description . ' - Visit now!';
@gerbenjacobs gerbenjacobs added this to the v2.0.0 milestone Dec 4, 2015
@DavydeVries
Copy link
Contributor

The best way is #1 (I prefer this method), but I understand why other developers like to use #3 is al lot easier to access. Because you access this like json data/object.

@gerbenjacobs
Copy link
Owner Author

Alright, since I have no real preference and there's no other suggestions, let's stick with what we have, which is option 1.

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

No branches or pull requests

2 participants