gerbenjacobs / HabboAPI

A PHP wrapper for the (undocumented) Habbo API
MIT License
44 stars 10 forks source link

Getters #12

Closed gerbenjacobs closed 8 years ago

gerbenjacobs commented 8 years ago

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!';
DavydeVries commented 8 years ago

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 commented 8 years ago

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