PHP比你想象的好得多

PHP比你想象的好得多

有很多对于PHP的抱怨,甚至这些抱怨也出自很多聪明的人。当Jeff Atwood写下对于PHP的另一篇抱怨文章之后,我思考了下PHP的好的方面。

这些抱怨最大的问题是他们出自很多仍在使用旧版本PHP的人。他们或许是不愿意关心或许是不愿意承认PHP不管在语言层面还是在社区层面都在以很快的速度演变。实际上它比任何其他语言或者web平台都演变的快。尽管并不总是如此,但是过去的五年PHP经历了一个惊人的历程。

在说最近PHP社区取得的惊人成就之前,我们先来看看一些有趣的数字:PHP被77.9%的服务端编程语言已知的网站使用。Wordpress被全世界16.6%的网站使用。使用率最高的三个CMS建站系统是:第一的Wordpress份额为54.3%,第二的Joomla份额为9.2%,第三的 Drupal份额为6.8%。这三个产品都是用PHP写的。

PHP一定做了一些正确的事,不是吗?

现在,我来告诉你吧,PHP的绝技在于:尽管经过了这么多年的变化,PHP对于非技术人员依然是最容易学习的语言,它让人可以比其他技术更快地建立动态网站,也让人没有麻烦地托管网站。PHP可能不是这个世界上设计最好的语言,但是它能让你完成事情(get things done),这一点是毋庸置疑的。

PHP语言

PHP5.0(2004年发布)带来了很实用的对象模型…等等,我在说8年前发布的东西。快进到现在的PHP5.4,即PHP最近的版本,带来了对于现代web语言你梦寐以求的东西:是的,PHP支持了命名空间(namespaces);是的,PHP支持闭包(closure);是的,PHP支持 traits。

尽管需要花费一些时间,但是PHP5.4带来了一些语法糖使得整体体验比以往更好:是的,PHP支持用[ ]定义数组;是的,PHP支持新创建的对象这样调用函数:(new Foo())->bar();是的,PHP支持数组这样获取元素:$foo->bar()[1]。

PHP甚至向它自己曾犯过的错误学习:register_globals 和 magic_quotes被彻底删除了。

PHP有了内置web服务器以方便本地测试,它能以微秒级的速度启动。

接下来的挑战:我们怎样更新在网络上的讲解PHP的教程?在PHP程序中最好的支持WebSocket的技术是什么?

PHP生态系统

拥有一个好的语言是很好的,但是拥有一个好的生态系统更棒。在过去的几年PHP生态系统演变了很多。

Git

对于Git我不想讨论太多,Git被到处使用,PHP很快拥抱了Git。几乎所有PHP类库、框架和产品都在使用Git,包括PHP本身。

Composer

两年前,我想去掉我在symfony 1中hack的丑陋PEAR代码以支持插件。我想替换成能管理项目依赖的东西,而不是一个像PEAR一样的整体的安装,所以我试着寻找能管理软件依赖的最佳的算法。我几乎尝试了所有可能:从Perl到Ruby,从Debian到Redhat。结果没有让我满意的,只有我自己的解决方案恰巧能工作…当然这只是我的经验只谈。之后我偶然发现了ZYpp,就是它了。ZYpp使用布尔可满足性问题解来管理依赖。多亏了Nils AdermannJordi Boggiano的辛苦工作,PHP现在有了做好的管理依赖的工具–Composer

是的,PHP比其他语言有了更好的依赖管理工具。

由于有了Git,Composer,和PHP内置web服务器,我们更容易下载/测试/安装一个PHP项目。

想测试Symfony(使用PHP5.4)?

 
  1. $ composer.phar create-project symfony/framework-standard-edition  
  2. $ cd framework-standard-edition  
  3. $ ./app/console server:run 

想测试Silex?

 
  1. $ composer.phar create-project fabpot/silex-skeleton  
  2. $ cd silex-skeleton  
  3. $ php -S localhost:8888 -t web/ 

还不知道Composer?你应该了解下它了。

浏览下主要的Composer仓库Packagist,它已经拥有1900多个包,且它们在不到三个月的时间里被安装了上百万次。

接下来的挑战:在下一个PHP版本里内置Composer?

合作

社区合作是本文说的重点,也是我最引以为豪的地方。我们开始看到PHP项目中更好的合作,甚至大项目也是如此,大到你可以忽略其他项目了。

phpBB,Drupal,ez Publish,Symfony,和很多其他项目(比如phpDocumentor, PHPUnit, Behat, Zikula, Propel, Doctrine, Midgard等等)都在共享代码。是的,他们彼此是竞争者,但是他们都理解彼此合作是很重要的。Composer能很好地促进这种合作。

接下来的挑战:说服更多的项目加入这个趋势中来。

结论

让我再重申一次,PHP可能不是最好的编程语言,我也是第一个说出它的怪处的,但是PHP是迄今为止最好的web平台。

原文链接:http://hp.dewen.org/?p=1572

##################################################################################### ## ## MOD Title: AUCTION MOD 1.3m ## MOD Author: FR (www.phpbb-auction.com) ## MOD Description: - ## MOD Version: 1.3m ## ## Installation Level: (Middle) ## Installation Time: till your done ## ## Requirements: A running phpBB 2.0.x (lastest version recommended) ## GD 1.8.x - 2.0 or higher (require for auto-thumbnail ## HTTP File Upload Enabled ## ## Tested with: __________ ## ## Files To Edit: viewonline.php ## viewtopic.php ## admin/index.php ## includes/usercp_viewprofile.php ## includes/page_header.php ## language/lang_english/lang_admin.php ## language/lang_english/lang_main.php ## templates/subSilver/subSilver.cfg ## templates/subSilver/overall_header.tpl ## templates/subSilver/viewtopic_body.tpl ## templates/subSilver/profile_view_body.tpl ## ## Included Files: to much to mention ## ##################################################################################### ## ## Before Adding This MOD To Your Forum, You Should Back Up All Files ## Related To This MOD ## ##################################################################################### ## ## For Security Purposes, you should check www.phpbb-auction.com for news and patches ## ##################################################################################### ## ## Author Notes: ## ## ##################################################################################### ## ## This hack is released under the GPL License. ## This hack can be freely used, but not distributed, without permission. ## Intellectual Property is retained by the author listed above. ## ##################################################################################### # # If you have the phpbb-auction 1.2m installed you should use the update.txt # document. # # #-----[ COPY ]------------------------------------------------------- # # Upload all files in directory "phpbb_root" with their structure to your # phpBB root directory # # Remember to upload all the language files and template files to all your # language packs and template directories # # If you use FTP please remember to use ASCII mode for text files (*.php, *.tpl) # and BINARY mode for image files (*.jpg, *.gif) # Fortunately good FTP clients today can auto-detect the mode for your files # #-----[ ACTION ]-------------------------------------- # Require for Unix-like host (you can use your FTP client to do this) # # CHMOD 777 auction/upload/ # CHMOD 777 auction/upload/cache/ # CHMOD 777 auction/upload/main/ # CHMOD 777 auction/upload/main/watermark/ # CHMOD 777 auction/upload/mini/ # CHMOD 777 auction/upload/tmp/ # CHMOD 777 auction/upload/wmk/ # CHMOD 777 auction/upload/watermark/ # CHMOD 777 auction/upload/wmk/main_watermark.png # CHMOD 777 auction/upload/wmk/big_watermark.png # #-----[ ACTION ]-------------------------------------- # # Run the install_db.php and delete (!!!) the file afterwards //////////////////////////////////////////////////////////////////////////////// 3 - Perform the following filechanges //////////////////////////////////////////////////////////////////////////////// # #-----[ OPEN ]------------------------------------------ # viewonline.php # #-----[ FIND ]------------------------------------------ # include($phpbb_root_path . 'includes/page_header.'.$phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # include($phpbb_root_path . 'auction/auction_common.'.$phpEx); # #-----[ FIND ]------------------------------------------ # case PAGE_FAQ: $location = $lang['Viewing_FAQ']; $location_url = "faq.$phpEx"; break; # #-----[ AFTER, ADD ]------------------------------------------ # case AUCTION_ROOM: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_OFFER: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_RATING: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_FAQ: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_MYAUCTION: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_OFFER_VIEW: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_SITEMAP: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; case AUCTION_PIC_MANAGER: $location = $lang['Auction']; $location_url = "auction.$phpEx"; break; # #-----[ OPEN ]------------------------------------------ # admin/index.php # #-----[ FIND ]------------------------------------------ # require('./pagestart.' . $phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # include($phpbb_root_path . 'auction/auction_common.'.$phpEx); # #-----[ FIND ]------------------------------------------ # # 2 times case PAGE_FAQ: $location = $lang['Viewing_FAQ']; $location_url = "index.$phpEx?pane=right"; break; # #-----[ AFTER, ADD ]------------------------------------------ # # 2 times case AUCTION_ROOM: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_OFFER: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_RATING: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_FAQ: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_MYAUCTION: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_OFFER_VIEW: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_SITEMAP: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; case AUCTION_PIC_MANAGER: $location = $lang['Auction']; $location_url = "auction.$phpEx?pane=right"; break; # #-----[ OPEN ]------------------------------------------ # /language/lang_english/lang_admin.php # #-----[ FIND ]------------------------------------------ # $lang['Styles'] = 'Styles Admin'; # #-----[ AFTER, ADD ]------------------------------------------ # $lang['Auction'] = 'Auction'; $lang['a1_configuration'] = 'Configuration'; $lang['a2_roommangement'] = 'Manage Rooms'; $lang['a4_coupons'] = 'Manage Coupons'; $lang['a3_offer'] = 'Manage Offers'; $lang['a5_ipn_log'] = 'Manage IPN Log'; $lang['a6_picture_Configuration'] = 'Manage Images'; $lang['a7_permission'] = 'Manage Permissions'; $lang['a8_account'] = 'Manage Account'; # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/subSilver.cfg # #-----[ FIND ]------------------------------------------ # $current_template_images = $current_template_path . "/images"; # #-----[ AFTER, ADD ]------------------------------------------ # $images['auction_locked']="$current_template_images/auction_locked.gif"; $images['auction_open']="$current_template_images/auction_open.gif"; $images['icon_auction_delete']="$current_template_images/auction_delete.gif"; $images['icon_auction_move']="$current_template_images/auction_move.gif"; $images['icon_auction_pic']="$current_template_images/auction_pic.gif"; $images['icon_auction_no_pic']="$current_template_images/auction_nopic.gif"; $images['icon_auction_down']="$current_template_images/auction_down.gif"; $images['icon_auction_up']="$current_template_images/auction_up.gif"; $images['icon_auction_feature']="$current_template_images/auction_feature.gif"; $images['icon_rating1']="$current_template_images/rating/1.gif"; $images['icon_rating2']="$current_template_images/rating/2.gif"; $images['icon_rating3']="$current_template_images/rating/3.gif"; $images['icon_rating4']="$current_template_images/rating/4.gif"; $images['icon_auction_watch']="$current_template_images/auction_add.gif"; $images['icon_auction_user_rating'] = "$current_template_images/{LANG}/icon_auction_user_rating.gif"; $images['newoffer'] = "$current_template_images/{LANG}/newoffer.gif"; $images['direct_sell'] = "$current_template_images/{LANG}/auction_buy_now.gif"; $images['vote_left'] = "$current_template_images/vote_lcap.gif"; $images['vote_right'] = "$current_template_images/vote_rcap.gif"; $images['auction_vote_right'] = "$current_template_images/auction_voting_barb.gif"; $images['auction_vote'] = "$current_template_images/auction_voting_bar.gif"; # #-----[ OPEN ]------------------------------------------ # /language/lang_english/lang_main.php # #-----[ FIND ]------------------------------------------ # $lang['datetime']['Dec'] = 'Dec'; # #-----[ AFTER, ADD ]------------------------------------------ # // Auction $lang['Auction'] = 'Auction'; # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/overall_header.tpl # #-----[ FIND ]------------------------------------------ # <a href="{U_GROUP_CP}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_groups.gif" width="12" height="13" border="0" alt="{L_USERGROUPS}" hspace="3" />{L_USERGROUPS}</a> # #-----[ AFTER, ADD ]------------------------------------------ #   <a href="{U_AUCTION}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_auction.gif" width="12" height="13" border="0" alt="{L_AUCTION}" hspace="3" />{L_AUCTION}</a> # #-----[ OPEN ]------------------------------------------ # includes/page_header.php # #-----[ FIND ]------------------------------------------ # 'L_FAQ' => $lang['FAQ'], # #-----[ AFTER, ADD ]------------------------------------------ # 'L_AUCTION' => $lang['Auction'], # #-----[ FIND ]------------------------------------------ # 'U_FAQ' => append_sid('faq.'.$phpEx), # #-----[ AFTER, ADD ]------------------------------------------ # 'U_AUCTION' => append_sid('auction.'.$phpEx), # #-----[ OPEN ]------------------------------------------ # viewtopic.php # #-----[ FIND ]------------------------------------------ # include($phpbb_root_path . 'includes/bbcode.'.$phpEx); # #-----[ AFTER, ADD ]------------------------------------------ # // Start Include language file $language = $board_config['default_lang']; if( !file_exists($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.'.$phpEx) ) { $language = 'english'; } include($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.' . $phpEx); // end include language file # #-----[ FIND ]------------------------------------------ # 'L_MINI_POST_ALT' => $mini_post_alt, # #-----[ AFTER, ADD ]------------------------------------------ # 'AUCTION_USER_RATING' => "<a href=" . append_sid("auction_rating.php?mode=view&" . POST_USERS_URL . "=" .$poster_id ) . "><img src=" . $images['icon_auction_user_rating'] . " alt='Feedback Rating' border='0' /></a>", 'L_VIEW_AUCTION_USER_RATING' => $lang['auction_user_rating'], # #-----[ OPEN ]------------------------------------------ # includes/usercp_viewprofile.php # #-----[ FIND ]------------------------------------------ # if ( !defined('IN_PHPBB') ) { die("Hacking attempt"); exit; } # #-----[ AFTER, ADD ]------------------------------------------ # // Start Include language file $language = $board_config['default_lang']; if( !file_exists($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.'.$phpEx) ) { $language = 'english'; } include($phpbb_root_path . 'language/lang_' . $language . '/lang_auction.' . $phpEx); // end include language file # #-----[ FIND ]------------------------------------------ # 'AVATAR_IMG' => $avatar_img, # #-----[ AFTER, ADD ]------------------------------------------ # 'AUCTION_USER_RATING' => "<a href=\"" . append_sid("auction_rating.php?mode=view&" . POST_USERS_URL . "=" . $profiledata['user_id'] ) . "\"><img src=\"" . $images['icon_auction_user_rating'] . "\" alt=\"" . $lang['auction_user_rating'] . "\" title=\"" . $lang['auction_user_rating'] . "\" border=\"0\" /></a>", 'L_VIEW_AUCTION_USER_RATING' => $lang['auction_user_rating'], # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/viewtopic_body.tpl # #-----[ FIND ]------------------------------------------ # {postrow.MSN_IMG} # #-----[ AFTER,ADD ]------------------------------------------ # // Goes in same line before {postrow.MSN_IMG} {postrow.AUCTION_USER_RATING} # #-----[ OPEN ]------------------------------------------ # /templates/subSilver/profile_view_body.tpl # #-----[ FIND ]------------------------------------------ # <tr> <td valign="middle" nowrap="nowrap" align="right"><span class="gen">{L_AIM}:</span></td> <td class="row1" valign="middle"><span class="gen">{AIM_IMG}</span></td> </tr> # #-----[ AFTER, ADD ]------------------------------------------ # <tr> <td valign="middle" nowrap="nowrap" align="right"><span class="gen">{L_VIEW_AUCTION_USER_RATING}:</span></td> <td class="row1" valign="middle"><span class="gen">{AUCTION_USER_RATING}</span></td> </tr> # #-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ # ##################################################################################### ## Further Information ## ## Thats it! You are through. If you have any questions dont hesitate to use the ## Support Forums on www.phpbb-auction.com. If you want to use the payment methods ## you should read the documentation for it on the projects website. ## Greetings and have fun with phpbb-Auction ## FR ## EoM #####################################################################################
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值