PHP 5.3 เปลี่ยนอะไรบ้าง (php version 5.3.x)
สวัสดีครับ ช่วงนี้ต้องรวบรวมข้อมูลสำหรับทำงาน เลยถือโอกาสเขียนเป็นบทความเอาไว้ให้หลายๆท่านได้อ่านกัน ที่จริงแล้วส่วนนี้มีคนเขียนไว้ค่อนข้างจะเยอะครับ ลอง search ดูก็น่าจะเจอเยอะอยู่เหมือนกันครับ และคำอธิบายก็จะไกล้ๆเคียงกัน เพราะที่มาก็มาจาก php.net เหมือนกันเกือบทั้งหมดครับ บางที่ก็ไป copy เขามาต่อๆกันไป สำหรับบทความใน siammodify นี้หากผู้ใด copy ไปช่วยติดลิ้งค์กลับด้วยนะครับ
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 เข้ามาหรือมีการปรับเปลี่ยนสามารถดูเพิ่มเติมได้จากลิ้งค์นี้ครับ
http://th.php.net/manual/en/migration53.parameters.php
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 สามารถอ่านเพิ่มเติมได้ที่นี้นะครับ
http://th.php.net/manual/en/migration53.ini.php
ขอนอกเรื่องอีกนิดนึงนะครับ
พอดีผมได้เจอหลายๆเว็บเขียนบทความเกี่ยวกับ 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 PHP 5.3.x
http://th.php.net/manual/en/migration53.other.php
ผมหวังว่าบทความน่าจะเป็นประโยชน์แก่ใครหลายๆคนนะครับ และ หากท่านใดเอาทบความที่ผมเขียนนี้ไปใช้งาน ช่วยกรุณาใส่ลิ้งค์กลับมายังเว็บผมด้วยนะครับ และหากมีจุดใหนที่ผิดหรือเพี้ยนไปก็ต้องขออภัยด้วยนะครับ และแจ้งมาได้ครับทางผมจะได้แก้ไขให้ถูกต้อง ขอบคุณครับ