Intend to write these interfaces for others to use, think of two methods, do not know the kind of better
The first method interface, this kind of expansion is troublesome, and the position is fixed
Public function Student ($name, $age, $sex)
The second method of interface, write array
Public function student ([' name ' = $name, ' age ' = ' $age, ' sex ' + $sex])
Excuse me, that's better.
Reply to discussion (solution)
As an interface, of course, to explicitly specify the parameters
Can't I just get a parameter and get the result?
Recommend the first kind.
The second is easy to use, but if teamwork is troublesome.
As an interface, of course, to explicitly specify the parameters
Can't I just get a parameter and get the result?
Also, the main method inside the argument location is fixed dead, not very friendly.
In fact, interface is the object of communication between the norms, no rules inadequate surrounding area
Your second plan is not without merit, but because of the constraint is not strong, you need to use caution
Recommend the first kind.
The second is easy to use, but if teamwork is troublesome.
However, the elements of the method need to be encrypted in order to prevent changes in the transmission process, $params is the number of groups [$name, $sex, $age]
Yii:: $app->siteapi->check ($functionName, $params =[], Encryption::encrypt ($params))
I think it's up to you to look at your needs, assuming you have registered accounts, mailboxes, names, and system-generated userid, then the method should be
function register ($user _id, $email, $name)
But if the user information is updated, and the user information includes a lot of such as phone, nickname, QQ, school, gender, hobbies and so on, and can support a single field update, then it is best to pass an array
function Update_info ($user _info)
The second better, easy compatibility with the old version, the extensibility is very strong, suitable for the continuous iterative system
It's hard to say, look at the situation.
In the first form, the specification
In the second case, replace the array with the object:
Interfacepublic function Student (student $student)//classpublic function student (student $student) { $this- >student = $student;};/ /studentprotected $data = [ ' name ' = ' xxx ', ' age ' = ' 0 ', ' sex ' = 0,];//geter//seter
It is not very good to use arrays directly without restrictions. There is no limit, sometimes it is convenient, but things are too much, messy.
The advice of my friends upstairs is very good.