วันเสาร์ที่ 5 มกราคม พ.ศ. 2556

การปรับ โค๊ต เป็น PHP 5.3 เปลี่ยนอะไรบ้าง


การปรับ โค๊ต เป็น PHP 5.3

PHP 5.3 เปลี่ยนอะไรบ้าง (php version 5.3.x)

อ่านสาระความรู้ เกี่ยวกับการทำ้เว็บไซต์ และ ทำ SEO ได้ที่ เว็บไซต์ cms-4u.com

            ตอนนี้ เป็นที่ทราบกันดีว่า ทาง php  มีการแจ้งเกี่ยวกับการยกเลิก PHP5.2 เปลี่ยนมาเป็น PHP5.3 กันแล้ว  ซึ่ง สงผลกับเว็บไซต์ที่เขียนด้วย PHP ที่ยัง ใช้ฟังก์ชั่นต่างๆ กับ PHP 5.2 อยู่  หาก ทางผู้ให้บริการเว็บโฮสต์ติ้งมีการอัพเกรด เป็น PHP 5.3 แล้ว แน่นอนครับ ส่งผลกระทบต่อเว็บไซต์ที่ยังเป็น PHP 5.2 อยู่เป็นแน่ ดังนั้น ทาง cms-4u.com  จึง รวบรวมแนวทางการแก้ไข php function ให้สามารถรองรับกับ PHP 5.3 ในอนาคต สำหรับ ท่านผู้จัดทำเว็บไซต์ครับ
php function บางตัวที่จะถูกตัดออกไปใน php version 5.3
call_user_method()
call_user_method_array()
defin_syslog_variables()
dl()
ereg()
ereg_replace()
eregi()
eregi_replace()
set_magic_quotes_runtime()
session_register()
session_unregister()
session_is_register()
set_socket_blocking()
split()
spliti()
sql_regcase()
mysql_db_query()
mysql_escape_string()
ตัวอย่าง
erigi() become => preg_match(‘/theregex/i’) or => preg_match(‘#theregex#i’)
ereg_replace become => preg_replace(‘/theregex/’) or => preg_replace(‘#theregex#’)

       function ที่ถูกตัดออกไปผมว่าน่าจะส่งผลกระทบต่อโปรแกรมหลายๆโปรแกรมครับเนื่องด้วยบาง function ค่อนข้างเป็นที่นิยมตรงส่วนนี้ก็คงต้องไล่ๆปรับกันแหละครับ เช่นพวก ereg ต่างๆและ split รวมไปถึง mysql_db_query ที่เวลาผมแกะโปรแกรมบางตัวก็มักจะเจออยู่บ่อยๆครับ

และสำหรับเรื่องคุณสมบัติจะมีการยกเลิกบางอย่าง ซึ่งคุณสมบัติที่ถูกยกเลิก คือ
- การส่งค่าแบบ reference ( Assigning the return value of new by reference is now deprecated. )
- Call-time pass-by-reference is now deprecated.

สำหรับ function Deprecated features in PHP 5.3.x สามารถอ่านเพิ่มเติมได้ที่นี่นะครับ
http://th.php.net/manual/en/migration53.deprecated.php

นอกจากจะตัด function บางตัวออกไปแล้วสำหรับบาง function ก็มีการเพิ่ม Parameters เข้ามาดังนั้นเราอาจจะจำเป็นต้องไปใส่ Parameters ให้กับ function เหล่านั้นให้ถูกต้องตามด้วยครับ
รายชื่อตัวอย่าง function ที่มีการเพิ่ม Parameters เข้ามา
clearstatcache() – Added clear_realpath_cache and filename.
copy() - Added a stream context parameter, context.
fgetcsv() – Added escape.
ini_get_all() – Added details.
nl2br() – Added is_xhtml.
parse_ini_file() – Added scanner_mode.
round() - Added mode.
stream_context_create() – Added params.
strstr() and stristr() – Added before_needle.
function ที่มีการเพิ่ม Parameters เข้ามาหรือมีการปรับเปลี่ยนสามารถดูเพิ่มเติมได้จากลิ้งค์นี้ครับ

Seagull Framework
ผมขอเอ่ยถึงตัว seagull framework สักนิดนะครับ สำหรับ seagull framework ใน version เก่าๆจะมีเรียกใช้ function พวก call_user บางตัวครับ ในส่วนนี้เท่าที่หาดูมีการแจ้งออกมา และทางทีมงาน เขาก็ได้ทำการ fix bug ไปเรียบร้อยแล้ว ปัญหาจะเจอประมาณ
SectionMgr, NavigationDAO::addSection และ NavigationDAO::updateSection
โดยทำการปรับเปลี่นเป็น
return call_user_func_array(array($delegate, $methodName),$parameters);
สำหรับ seagull หากมีข้อผิดพลาดประการใดก็ต้องขออภัยด้วยนะครับ

และในส่วนของ php.ini ก็จะมีการยกเลิกบางอย่างออกไปครับ ตัวใหนผมอธิบายได้จะช่วยอธิบายคร่าวๆไว้ให้นะครับ
register_globals แปลว่าการเขียนรับค่าตัวแปรจะต้องเปลี่ยนไปใช้ ( $_REQUEST, $_GET, $_POST, $_SESSION, $_SERVER ) เท่านั้นครับ
define_syslog_variables
register_long_arrays
safe_mode
magic_quotes_gpc
magic_quotes_runtime
magic_quotes_sysbase
สำหรับเรื่อง Changes to INI file handling สามารถอ่านเพิ่มเติมได้ที่นี้นะครับ

ขอนอกเรื่องอีกนิดนึงนะครับ
พอดีผมได้เจอหลายๆเว็บเขียนบทความเกี่ยวกับ PHP 5.3 หน้าตาเนื้อหาก็คล้ายๆกัน แต่ผมชอบจุดที่อธิบายสั้นๆแต่เข้าใจได้คือ
# ereg, eregi, ereg_replace, eregi_replace เปลี่ยนไปใช้ตระกูล perl compatible regular expressions (preg*)
# split เปลี่ยนไปใช้ preg_split แทน
# mysql_db_query เปลี่ยนไปใช้ mysql_select_db แล้วตามด้วย mysql_query
# mysql_escape_string เปลี่ยนไปใช้ mysql_real_escape_string
# register_globals เปลี่ยนไปใช้ Built-in global variables ($_REQUEST, $_GET, $_POST, $_SESSION, $_SERVER)
# session_register, session_is_register, session_unregister เปลี่ยนไปใช้ $_SESSION

เพียงแค่จุดนี้ก็ช่วยสรุปจุดสำคัญที่เราใช้กันบ่อยๆได้มากทีเดียวครับ

จากทั้งหมดนี้ท่านสามารถอ่านเพิ่มเติมได้ที่ลิ้งค์เหล่านี้นะครับ
What has changed in PHP 5.3.x
http://th.php.net/manual/en/migration53.changes.php
Backward Incompatible Changes in PHP 5.3.x
http://th.php.net/manual/en/migration53.incompatible.php
New features in PHP 5.3.x
http://th.php.net/manual/en/migration53.new-features.php
Changes made to Windows support in PHP 5.3.x
http://th.php.net/manual/en/migration53.windows.php
Changes in SAPI modules in PHP 5.3.x
http://th.php.net/manual/en/migration53.sapi.php
Undeprecated features in PHP 5.3.x
http://th.php.net/manual/en/migration53.undeprecated.php
New Functions in PHP 5.3.x
array_replace() – Replaces elements from passed arrays into one array.
array_replace_recursive() – Recursively replaces elements from passed arrays into one array.
class_alias() – Creates an alias for a user defined class.
forward_static_call() – Call a user function from a method context.
forward_static_call_array() – Call a user function from a method context, with the arguments contained in an array.
gc_collect_cycles() – Forces collection of any existing garbage cycles.
gc_disable() – Deactivates the circular reference collector.
gc_enable() – Activates the circular reference collector.
gc_enabled() – Returns the status of the circular reference collector.
get_called_class() – Return the name of the class a static method is called in.
gethostname() – Return the current host name for the local machine.
header_remove() – Removes an HTTP header previously set using the header() function.
lcfirst() – Make a string’s first character lowercase.
parse_ini_string() – Parse a configuration string.
quoted_printable_encode() – Convert an 8 bit string to a quoted-printable string.
New Functions in PHP 5.3.x
http://th.php.net/manual/en/migration53.functions.php
New stream wrappers in PHP 5.3.x
http://th.php.net/manual/en/migration53.new-stream-wrappers.php
New stream filters in PHP 5.3.x
http://th.php.net/manual/en/migration53.new-stream-filters.php
New Class Constants in PHP 5.3.x
http://th.php.net/manual/en/migration53.class-constants.php
New Methods in PHP 5.3.x
http://th.php.net/manual/en/migration53.methods.php
New Extensions in PHP 5.3.x
http://th.php.net/manual/en/migration53.new-extensions.php
Removed Extensions in PHP 5.3.x
http://th.php.net/manual/en/migration53.removed-extensions.php
Other changes to extensions in PHP 5.3.x
http://th.php.net/manual/en/migration53.extensions-other.php
New Classes in PHP 5.3.x
http://th.php.net/manual/en/migration53.classes.php
New Global Constants in PHP 5.3.x
http://th.php.net/manual/en/migration53.global-constants.php
Other changes in HP 5.3.x
http://th.php.net/manual/en/migration53.other.php

ผมหวังว่าบทความน่าจะเป็นประโยชน์แก่ใครหลายๆคนนะครับ และ หากท่านใดเอาทบความที่ผมเขียนนี้ไปใช้งาน ช่วยกรุณาใส่ลิ้งค์กลับมายังเว็บผมด้วยนะครับ และหากมีจุดใหนที่ผิดหรือเพี้ยนไปก็ต้องขออภัยด้วยนะครับ และแจ้งมาได้ครับทางผมจะได้แก้ไขให้ถูกต้อง ขอบคุณครับ

อ่านสาระความรู้ เกี่ยวกับการทำ้เว็บไซต์ และ ทำ SEO ได้ที่ เว็บไซต์ cms-4u.com

ไม่มีความคิดเห็น:

แสดงความคิดเห็น