What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.
-
Upload
benedict-barker -
Category
Documents
-
view
216 -
download
1
Transcript of What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.
What Does PHP 5.3 Mean for Drupal?
C.M. LubinskiDrupal Camp Chicago
2010-06-26
And you are . . . ?
C.M. Lubinski • By Day: PHP Developer• By Night: Drupal Enthusiast• By Interest: Language Connoisseur
• cmc on #cdmug
What's all this then?
• New Features, Top Five-ish• Problems and Incompatibilities• Hopes and Realities of Drupal Core
Number Five: Garbage Collection
PHP < 5.3• Reference Counting• Does Not Catch Cyclic References
o Example: Doubly-Linked Listo Not a big problem for Drupal
New Functions• gc_enable / gc_disable / gc_enabled • gc_collect_cycles
Number Four: Date/Time Changes
DateInterval• Object with fields for each unit• DateTime->add/sub• DateTime->diff• Not as intelligent as one would hope
DatePeriod• "Traversable" (i.e. foreach-able)• Constructors:
o Start, Interval, Number of Occurrenceso Start, Interval, End o ISO String
Number Three: New SPL Classes
Data Structures• SplDoublyLinkedList• SplStack• SplQueue, SplPriorityQueue • SplHeap, SplMinHeap, SplMaxHeap• SplFixedArray
Iterators• FilesystemIterator• GlobIterator• MultipleIterator• etc.
Number Two: Anonymous Functions and Closures
Anonymous Function1.A function that can be passed as a variable– An object which can be called
Closure ("use")• An anonymous function with state• Cannot be serialized
Use Cases• Anywhere a callback is needed• Sort• String Replacement• *Not* Drupal Menu Callbacks
Number One point Five: __invoke()
• Treat an object as a function• Can be used as a callback • Serializable closure
Use Cases• Factories
o Track Generated Instances • Compound Function (e.g. SQL query) • Conciseness
Number One: Namespaces
• Modularize Code• Can Alias a Namespace• class_name() includes absolute path • Offers OO Benefits Without Objects • Not Dynamic
o Cannotuse 'Drupal\Modules\' . $module_name;
o Can$func = 'Drupal\Modules\' . $module_name . '\
Hooks\menu';
But That's Not All!
• PHAR, the PHP archive• MySQL driver is now native• ?: • Improvements to static classes/methods• array_replace • Faster!• Even more
Not Without Its Problems: GOTO
goto 'beginning';logic: the logical progression of the program. exit();beginning: GOTO makes code goto 'stringy';point: to the point where it's hard to understand goto 'logic';stringy: needlessly unreadable goto 'point';
Incompatibilities: Ereg is Dead
• Represents regular expressions for egrep• Defined in 1986• Not as powerful (or fast) as preg_*
o No \w, \s, etc.o No lazy evaluationo No "look-around"s
• Converting is simpleo Wrap previous regex is appropriate delimiter
• split is also dead
Incompatibilities: By-Reference
• Call-time pass-by-reference has been deprecated• Don't use references when calling functions
o Except call_user_func_array • Caused many issues with D6• allow_call_time_pass_reference in php.ini
5.3 and Drupal Core
Drupal 6 • Still Supports PHP4• Drupal >= 6.14 Supports PHP 5.3
o Contrib does notDrupal 7 • Requires PHP 5.2• Contrib will have better support for 5.3• Use the "php" option in module.info• "Mapper" functions will still be needed
Drupal 8• Here's Hoping
References, Questions and a Book
http://us2.php.net/migration53http://drupal.org/node/360605
Thanks!CM Lubinski
http://cmlubinski.info