PHP: 言語リファレンス - Manual
PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<設定を変更するには基本的な構文>
view the version of this page
Last updated: Tue, 21 Dec 2004


add a note add a note User Contributed Notes
言語リファレンス
michael dot bommarito at gmail dot com
22-Feb-2005 07: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 10:45
I've created a PHP4 grammar for the Java based SableCC parser generator.

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.

<設定を変更するには基本的な構文>
 Last updated: Tue, 21 Dec 2004
show source | credits | sitemap | contact | advertising | mirror sites 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: /
Last updated: Mon Mar 14 08:13:06 2005 Local time zone must be set--see zic manual page