PHP vs OO PHP-使用哪个? [英] PHP vs OO PHP - Which one to use?

查看:78
本文介绍了PHP vs OO PHP-使用哪个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用常规PHP开发网络系统.这是我第一次使用PHP,因此代码不清晰也不清晰.它将一些HTML代码与PHP混合在一起. 我会说我已经完成了一半的代码.

I'm developing a web system using regular PHP. This was my first experience with PHP so the code is not legible nor clean. It mixes some HTML code with PHP. I'd say I have already done half of the code.

面向对象的PHP的真正优势是什么? 该网站是有关使用MySQL和Apache的书籍和书籍作者的.因此,这不是一个非常复杂的网站.

What are the real advantages of the Object-oriented PHP? The website is about books and book authors, using MySQL and Apache. So it's not a very complicated website.

推荐答案

面向对象的真正优势:您的代码组织得更好,更易于维护,更模块化(从而更易于重用),并且可能变脆( (因为封装了状态和实现,并希望有更好的安全性). (我心中的愤世嫉俗者还说,如果您学习面向对象的PHP,则迈出了重要的第一步,即离开了

The real advantage of object-orientation: your code is better organized, easier to maintain, more modular (and thus easier to reuse), and potentially less brittle (because of encapsulation of state and implementation, and hopefully better security). (The cynic in me also says that if you learn object-oriented PHP, you take the first important step to leaving the PHP ghetto. Heh. Worked for me!)

已经有很多来自PHPers的问题在Stack Overflow上进入OO:

There's already a lot of questions from PHPers moving into OO on Stack Overflow:

  • PHP Object Oriented or Not?
  • Is my PHP code object oriented?
  • Learning PHP Class

更不用说那里有成千上万的PHP面向对象的教程.我的看法:基本上,是的,如果您正在编写PHP,则可能应该为除最琐碎的应用程序之外的所有内容编写面向对象的PHP.有许多类似PHP的Rails框架,这些框架可以使您的生活更轻松,并可以帮助您成为更好的程序员.

Not to mention that there are zillions of PHP object-oriented tutorials out there. My take: basically, yes, if you are writing PHP, you should probably be writing object-oriented PHP for anything beyond the most trivial of applications. There are lots of Rails-like frameworks for PHP that will make your life easier, and may help you become a better programmer.

这篇关于PHP vs OO PHP-使用哪个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆