What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

15
What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26

Transcript of What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

Page 1: 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

Page 2: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal 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

Page 3: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

What's all this then?

• New Features, Top Five-ish• Problems and Incompatibilities• Hopes and Realities of Drupal Core

Page 4: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 5: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 6: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

Number Three: New SPL Classes

Data Structures• SplDoublyLinkedList• SplStack• SplQueue, SplPriorityQueue • SplHeap, SplMinHeap, SplMaxHeap• SplFixedArray

Iterators• FilesystemIterator• GlobIterator• MultipleIterator• etc.

Page 7: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 8: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 9: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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';  

Page 10: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

But That's Not All!

• PHAR, the PHP archive• MySQL driver is now native• ?: • Improvements to static classes/methods• array_replace • Faster!• Even more

Page 11: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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';

Page 12: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 13: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 14: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

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

Page 15: What Does PHP 5.3 Mean for Drupal? C.M. Lubinski Drupal Camp Chicago 2010-06-26.

References, Questions and a Book

http://us2.php.net/migration53http://drupal.org/node/360605

Thanks!CM Lubinski

http://cmlubinski.info