PHP Classes

File: Examples/common/aliases.bad.php

Recommend this page to a friend!
  Classes of Christian Vigh   PHP Command Line Arguments Parser   Examples/common/aliases.bad.php   Download  
File: Examples/common/aliases.bad.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Command Line Arguments Parser
Parse and extract arguments from the command line
Author: By
Last change: Update of Examples/common/aliases.bad.php
Date: 1 year ago
Size: 1,252 bytes
 

Contents

Class file image Download
<?php
   
/***
        This example defines a command line accepting several parameters, each of them
        having aliases.

        However, this script will fail with a CLException exception, because the -integer_value
        and -float_value parameters all define an alias with the same name, "val"
     ***/
   
require_once ( dirname ( __FILE__ ) . '/../examples.inc.php' ) ;

   
$definitions = <<<END
<command>
    <usage>
        This example defines a command line accepting several parameters, each of them
        having several unique aliases.
    </usage>

    <string name="string_value, strval, sv">
        Help for the string_value parameter (which can also be specified as -strval or -sv).
    </string>

    <integer name="integer_value, val, iv">
        Help for the -integer_value parameter (which can also be specified as -ival or -iv).
    </integer>

    <float name="float_value, val, fv">
        Help for the -float_value parameter (which can also be specified as -fval or -fv).
    </float>
</command>
END;

   
$cl = new CLParser ( $definitions ) ;
    echo
"Value of the -string_value parameter : {$cl -> string_value}\n" ;
    echo
"Value of the -integer_value parameter : {$cl -> integer_value}\n" ;
    echo
"Value of the -float_value parameter : {$cl -> float_value}\n" ;