search for in the  
<How to change configuration settingsBasic syntax>
Last updated: Thu, 19 May 2005


User Contributed Notes
Language Reference
michael dot bommarito at gmail dot com
22-Feb-2005 01:16
Posted this on the function-handling function page, but it seems it's a topic here too.

I've developed an easy-to-use hack using these functions to emulate overloaded functions.  It's especially handy for constructors and/or C++ style templating.

Here's a little example to get you going.  This does the trick for most circumstances, and if you need more intelligent parsing, it's not too hard to implement with regex or a more suitable classification scheme.

N.B. Note the lack of whitespace between variable types in case strings.

class Matrix {

...

function Matrix() {
  $args = func_get_args();
  $argmatch = implode(",", array_map('gettype', $args));

  switch( $argmatch ) {
   case 'integer,integer':
     //initialize m x n matrix
     break;

   case 'integer,integer,integer':
     //initialize m x n matrix with constant c
     break;

   case 'integer,integer,float':
     //initialize m x n matrix with constant c
     break; 

   case 'array':
     //initialize from array (2D....)
     break;

   case 'array,integer':
     //intialize from array (1D packed with m rows)
     break;
 
   default:
     //(void) overload?
     //error handling?
     break;
  }
}

...

}
Indrek Mandre <indrek(at)mare(dot)ee>
02-Sep-2003 05:45
I've created a PHP4 grammar for the Java based SableCC parser generator.
http://www.mare.ee/indrek/sablecc/
As there is no PHP language specification I can't guarantee its correctness but it seems to work on most files I've fed to it. It should make working on parsing PHP for various tasks a lot easier (loads easier than using the bison mess) but it's also only for Java.

<How to change configuration settingsBasic syntax>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT