Class PHP 中的姓名

Class name in PHP

您好,

我要class名字很具体。喜欢:form.class.phpdatabase.class.php 我通过自动加载访问它们。

但有时我需要一个不特定的功能。

例如:获取当前用户的头像两个用户之间的关系

我正在使用 function.class.php 来实现这些功能,但 function.class.php 正在成长。

我该怎么做?

请注意:英语不是我的母语。

此致。

In object-oriented programming, a class is a template that defines the state and behavior common to objects of a certain kind. A class can be defined in terms of other classes. For example, a truck and a racing car are both examples of a car. Another example is a letter and a digit being both a single character that can be drawn on the screen. In the latter example, the following terminology is used:

The letter class is a subclass of the character class; (alternative names: child class and derived class) The character class is immediate superclass (or parent class) of the letter class; The letter class extends the character class. The third formulation expresses that a subclass inherits state (instance variables) and behavior (methods) from its superclass(es). Letters and digits share the state (name, font, size, position) and behavior (draw, resize, ...) defined for single characters.

来源: https://staff.fnwi.uva.nl/a.j.p.heck/Courses/JAVAcourse/ch3/s1.html

如果您有用户,我假设您有 User class。如果你不这样做,你应该考虑做一个。在此用户 class 中,您可以存储所有 User 方法,例如:

class User{
    private $avatar;    

    public function getAvatar(){
        return $this->avatar;
    }

    public function setAvatar($avatar){
        $this->avatar = $avatar;
    }

    //etc.
}

你会像这样使用它们:

$user->getAvatar()
$user->getRelation($other_user);

编辑
感谢 Chris Baker 在评论中的补充。他为开始使用 OOP 的人指定了 this article。我也推荐看看!