Accessing backend system…

We're sorry, but your session has expired due to inactivity. Please use your browser to refresh this page and log in to our system again.

Message goes here.

Message goes here.

Message goes here.

LOGIN / REGISTER
VIEW BASKET
SEARCH:
 
php|architect logo
 
SERVICES
  • MAGAZINE
  • PHP|TEK 2012
  • CODEWORKS 2011/12 TOUR
  • BOOKS
  • TRAINING
  • ADVERTISE
 
CHANNELS
  • NEWS
  • PODCAST
  • DEVELOPMENT
  • OPINION
  • WRITE

Analysis: Following Ruby Makes PHP Number Two

Posted by Bill Karwin on September 23, 2010
IN News ·Opinion
Tags: oop · php
 

Related Posts:

  • First beta of Doctrine 2 released
  • php|tek’s Call for Papers is Closing Soon
  • Finding Exactly Where You Are
  • Geolocation: Easier Than It Looks
  • Building the Backside – Part 1

These days, people sure seem to be coming up with some… interesting names for their projects. Dennis Hotson, for example, wrote in his blog today about PHP Object Oriented Programming Reinvented.

That’s right—PHPOOPR.

Dennis acknowledges that the name needs work. But, getting past that, his blog is about some creative experiments Dennis is working on.  He has come up with a pretty innovative way of creating objects dynamically in PHP that allows for some usage that conventional PHP coding techniques don’t support:

  • Classes can be hacked / patched / cloned. Methods can be added to classes at any time.
  • Classes can be scoped. They’re not global, unless you want them to be.
  • Classes can be temporary (and garbage collected).

In Dennis’s code, class definitions are objects themselves, created by a base class constructor function Obj().

$class = Obj();

A Factory is a design pattern for an object that can create more objects of various types.  Thus, Obj() is a factory method.

The only thing that differentiates one class instance from another is the methods it supports.  You can add new methods to any class by passing a PHP closure to a class object.

$class->fn('new', function ($class) {
  $newClass = Obj($class->methods)
    ->fn('new', function($class) {
      $obj = Obj($class->imethods);
      $args = func_get_args();
      array_shift($args);
      call_user_func_array(array($obj, 'init'), $args);
      return $obj;
    });
  return $newClass;
});

Now, $class can create instances of the respective type, so these class objects are also factories, making Obj() a factory factory.

$object = $class->new();

You can make a class support subclassing by adding a new method to return a new class object, a clone that has the same functions:

$class->fn('extend', function($t) { return clone $t; });
$subclass = $class->extend();
$object = $subclass->new();

Since all classes are factories, extensible classes are therefore also factory factories.  Which makes Obj() a factory factory factory.

You can add more methods to each class instance, of course.

This is a very clever experiment. But I wonder if Dennis wants to program in the paradigm of everything-is-an-object like Ruby or Python, why doesn’t he just use Ruby or Python?

His experiment mimics what those languages have already done, but he still has some parts of PHP that developers hate, such as the motley, non-OO built-in functions, and the need for the array() syntax for array literals.

There are a number of other features of PHP’s conventional OOP that go out the window in Dennis’ code:

  • Compile-time typehints: Classes don’t even have names, they only have instances, which aren’t created until runtime.
  • instanceof: Likewise, you can’t test an object’s class for its type or any of its supertypes because types don’t have names. An object doesn’t know what type it is, only what methods it has.
  • Interfaces: Dennis doesn’t show how one would force an object to have a certain set of methods to conform to an interface, or how to make any given method have a specified signature.
  • Reflection: PHP’s built-in functionality for reporting meta-information about types doesn’t work with Dennis’ objects, so he’d have to reinvent that wheel.
  • SPL: All the types in SPL rely on conventional class extension and interface implementation, so they’re incompatible with Dennis’ objects.
  • Autoloading: PHP loads a class automatically if you reference it by its name, but if classes have no name, you have to take responsibility for loading the code that creates classes yourself.
  • ===: The idea of type equivalence is blurred. Two objects are “the same” if they simply have the same set of methods.
  • Code completion: In the same way that an IDE can’t infer the methods of an object implemented through the magic method __call(), these dynamic objects have functions that are not known until runtime, so intellisense has no idea what methods exist or what their signatures are.

The experiment Dennis is coding is worthwhile, but not because it will be useful. Instead, it’s worthwhile because it illustrates how we rely on the concept of a type in a programming language. Types enforce structure and help us depend on certain assumptions (like the interface of a class), so we can write simpler code. If we have limitless flexibility, we can’t rely on any structure remaining in place, so we have to write more complex code to handle an increasing amount of uncertainty and variation.

[Updated 09/28@18:52ET to fix the spelling of Dennis' last name (with our apologies)]


About the author—
 
 
 

MySQL, PostgreSQL Release Milestones

Posted by Bill Karwin on September 20, 2010
IN News
Tags: database · mysql · postgresql
 

Related Posts:

  • Lithium at version 0.7, now with SQL support
  • Crystal Starting to Form
  • PostgreSQL 9.0 beta released
  • MySQL Community Server 5.1.45 announced
  • Full-text Search with SQLite

This is a good week for open source databases.

MySQL 5.5 Release Candidate was announced at the MySQL Sunday event at Oracle OpenWorld.

Marketing-wise, Oracle obviously wants this release, as well as their special MySQL Sunday track, to show their commitment to MySQL.  Oracle Chief Corporate Architect Edward Screven and VP of MySQL Development Tomas Ulin announced the new release, and they described a schedule for MySQL 5.5 GA by the end of calendar year 2010.  Following through on this schedule will repair some of the PR damage from the year-long FUD and European Commission concerns about Oracle’s acquisition of Sun.

I was told the attendance of MySQL Sunday was on the order of 3000 people, many of whom comprise a previously untapped market of developers and DBA’a who use Oracle primarily, but also use MySQL in their environment, or are considering using MySQL (the “My-curious” market).  As part of Oracle, MySQL has already gained access to a larger community than they did on their own or as part of Sun.

MySQL 5.5 is still not GA, but it’s pretty close and you can get binaries from their download page, under the Development Releases tab.

The technology in this release has some pretty impressive and welcome features:

  • InnoDB is now the default storage engine, debunking some of MySQL haters’ main complaints.
  • InnoDB has been given huge performance improvements when serving at high scale, i.e. hundreds of concurrent connections.
  • New semi-synchronous replication, allows for greater throughput and integrity.  Replication heartbeat helps slaves keep in touch with the master.
  • Partitioning finally makes more sense, with new syntax for partitioning by range or list on date, datetime, char, and varchar columns.
  • SIGNAL & RESIGNAL (supporting standard ANSI/ISO SQL syntax) allow you to abort an operation from a trigger.  No more hacks like causing an error by assigning a string to an int variable in a trigger.
  • SHA2() function allows for much stronger hashing, in compliance with NIST policy.  This isn’t on the list of strongly-marketed new features, but it’s based on a patch that I submitted back in 2006, so I’m glad to see this finally see daylight.  You have to build MySQL against an SSL library for this function to be available.

Meanwhile, PostgreSQL 9.0 GA was announced today  I wrote in May about some of the features of this release, when they announced their 9.0 Beta.  PostgreSQL is also a strong open-source RDBMS (its license is New BSD-ish, just like PHP’s license) and it’s nice to see them go from Beta to GA in less than six months.  You can get their new release at their download page.


About the author—
 
 
 

CodeWorks is coming to a city near you!

Posted by Marco Tabini on
IN Conference
Tags: codework · Conference · CWX
 

Related Posts:

  • php|tek’s Call for Papers is Closing Soon
  • Check it out, tek 11 schedule is up!
  • Open source life style
  • PHP tours Europe in fall
  • phpDay 2010 international talks

After months of preparation, we’re excited to announce this year’s edition of our popular CodeWorks conference tour!

CodeWorks 2010 (CWX for short) is a series of one-day technical conferences presented by the php|architect team and sponsored by Adobe. It’s slated to stop in five cities, starting November 9th:

 

  • Seattle, WA (Nov. 9)

  • Portland, OR (Nov. 11)

  • Austin, TX (Nov. 13)

  • Baltimore, MD (Nov. 15)

  • Orlando, FL (Nov. 17)

Each stop features talks presented by the php|a gang on various PHP-related topics, including object orientation, scalability, security, development tools and efficiently building your own APIs. CWX is ideal for both developers at all levels and technical managers who want to get a handle on the latest techniques and developments in the PHP world.

Tickets to CWX are $100— if you purchase before September 30th you can take advantage of our early-bird program and save $25. Each ticket also comes with your very own annual subscription to php|architect—a $35 value—with our compliments!


About the author—Marco is the keeper of keys and Chief Garbage Collector at Blue Parabola, php|architect's parent company. He can be found on Twitter as @mtabini.
 
 
 

This month's issue

January 2012
Buy · $5 — Subscribe · starts at $35
 

 

Upcoming Training Courses

Course Start Date
Essential PHP 2012-02-03
AJAX Programming with PHP and … 2012-02-10
Essential Zend Framework 2012-02-17
Mobile HTML5, JavaScript and P… 2012-03-02
Professional PHP Development 2012-03-09
 

About us

  • What we do
  • Contact us
  • Write for us

Policies & legal

  • Customer support
  • Privacy policy
  • Refund policy
  • Terms & Conditions

Online Store

  • Magazine
  • Training courses
  • Books

Special sections

  • Codeworks 2011
 

Copyright © 2002-2012 Blue Parabola, L.L.C. — All amounts in USD - WP3