Looking for a way to handle/approach PHP OOP websites

前端 未结 3 1072
忘掉有多难
忘掉有多难 2020-12-09 23:19

I\'m not new to PHP or programming at all. But recently I was thinking about website programming in PHP and how easier it was before the OOP. Anyway, I prefer OOP than the o

3条回答
  •  自闭症患者
    2020-12-10 00:06

    I was thinking about website programming in PHP and how easier it was before the OOP

    Well, stick to procedural then. If it is easier to write a well written website in a procedural or functional way then opposed to the ojbect-oriented way. Stick ti what you are used to. OO isn't better then functional. It's just a different approach.

    the public void main() in php

    In the lanuage Java every piece of software we write has a single entry point. The public void main() method. This method fires up the entire application and passes in the arguments provided on startup. It is also the only exit point in the application. the application ends in this method (unless it crashes).

    In php, there is no single entry point. We have a bunch of files that run some scripts that do some more stuff and then somewhere along the line another script decides to return stuff and die();

    Dependency injection and how IoC libraries can help

    When using dependency injection, it becomes a real pain in the a$$ when creating objects and passing arround the correct instance of a class. We start solving this problem with ugly solutions: Singleton, globals, statics, ... Making our software more and more tightly coupled and harder to maintain.

    Inversion of Control can help here. there are some really greate articles on the webz.

提交回复
热议问题