Intro: What Pseudo_Block package is ?

Pseudo_Block improves usability of eval(), create_function(). You do not have to escape double/single quotations, back slashes in your eval(), create_function().

Pseudo_Block provides 'pseudo code block' way which not supported in PHP syntax natularry.

About

License

Apache Software License 2

Requirements

PHP(Unit Tested) : PHP 4.4.7 and 5.2.4

Maintainer

msakamoto-sf at users.sourceforge.net
(Another H.N : FengJing)

Installation and Usage

Latest Beta Release

Installation

Pseudo_Block is provieded as PEAR package. You can install it into your PEAR environment like below:

$ su (if you needed)
# pear install \
http://xhwlay.sourceforge.net/Pseudo_Block/Pseudo_Block-0.1.1.tgz

Are you a normal user, not administrator of your sever ? Don't worry. PEAR provides some means for normal users to setup PEAR environment in user's local/home environment.
Please refer PEAR Manual :
>>"Installation -> Getting Manager" (In English)
In Japanese, you can refer same manual here :
http://www.phppro.jp/phpmanual/pear/installation.getting.html

Follwing SVN(Subversion) repositry

  1. You must create accuont in SourceForge.net.
  2. You must understand usage of SVN tools.
  3. Try SVN checkout.
Subversion Server
https://xhwlay.svn.sourceforge.net
Path to Repositry
/svnroot/xhwlay
Example:
$ svn checkout \
https://xhwlay.svn.sourceforge.net/svnroot/xhwlay/Pseudo_Block
View only : http://xhwlay.svn.sourceforge.net/viewvc/xhwlay/

Usage 1 : Pseudo_Eval

<?php
require_once('Pseudo/Eval.php');

$pe =& new Pseudo_Eval();

// start pseudo block
$pe->start();
?>
// Here is pseudo block code.

$a = "ABC.";
$b = 'xyz.';
return $a . $b . $c;
// $c is binded value from outside of this block.

<?php
// end pseudo block
$pe->end();

$val 30;
// bind $val to '$c' to pseudo code block
// NOTE: you can't bind values by reference. (all value is passed by copy)
$pe->bind('c'$val);

// evaluate pseudo code block
$result $pe->act();

echo 
$result PHP_EOL;
// out : "ABC.xyz.30"
?>

Usage 2 : Pseudo_Lambda

<?php
require_once('Pseudo/Lambda.php');

// args is create_function()'s 1st args(function arguments)
$pl =& new Pseudo_Lambda('$a, $b');

// start pseudo block
$pl->start();
?>
// Here is pseudo block code.

static $c = 0;
$c++;

return $a + $b + $c + $d;
// $d is binded value from outside of this block.

<?php
// end pseudo block
$pl->end();

$val 30;
// bind $val to '$d' to pseudo code block
// NOTE: you can't bind values by reference. (all value is passed by copy)
$pl->bind('d'$val);

// create anonymous function (lambda) from pseudo code block
$func $pl->create();

echo 
$func(12) . PHP_EOL// out : 34 (1 + 2 + 1($c) + 30($d))
echo $func(34) . PHP_EOL// out : 39 (3 + 4 + 2($c) + 30($d))
?>

Usage 3 : Pseudo_Block

Pseudo_Block is super class of Pseudo_Eval and Psuedo_Lambda. It provides pseudo block text handling method. You can use pseudo block as raw data section like perl and ruby.

<?php
require_once('Pseudo/Block.php');

$pb =& new Pseudo_Block();

// start pseudo block
$pb->start();
?>
Name|Age|Hobbies
Masahiko|26|Programming
Sakamoto|62|Cooking
FengJing|-|Walking
<?php
// end pseudo block
$pb->end();

// get pseudo block text
$text $pb->getText();

$rows array_map('trim'explode("\n"$text));
foreach(
$rows as $row) {
    echo 
strtr($row"|"",") . PHP_EOL;
}
?>

Usage 4 : Pseudo_Perl (1)

<?php
require_once('Pseudo/Perl.php');

$pp =& new Pseudo_Perl();
$pp->setPerlBin('C:/Perl/bin/perl.exe -w');
$pp->start();
?>
while(<STDIN>) {
    print STDOUT $_;
    print STDERR "--", $_;
}
<?php
$pp
->end();

// we can communicate with invoked process 
// through stdin/out/err descriptor.
$pp->descriptors = array(
    
=> array('pipe''r'),
    
=> array('pipe''w'),
    
=> array('pipe''w'),
);
$pp->popen();

// now we pass some string datas to perl.
fwrite($pp->pipes[0], "ABC");
fwrite($pp->pipes[0], "DEF");
fclose($pp->pipes[0]);

// now we retrieve some string datas from perl.

$output fread($pp->pipes[1], 8192); // STDOUT
echo $output PHP_EOL;
fclose($pp->pipes[1]);

$output fread($pp->pipes[2], 8192); // STDERR
echo $output PHP_EOL;
fclose($pp->pipes[2]);

$pp->pclose();

Usage 5 : Pseudo_Perl (2)

<?php
require_once('Pseudo/Perl.php');

$pp =& new Pseudo_Perl();
$pp->setPerlBin('C:/Perl/bin/perl.exe -w');
// bind value (a)
$pp->bind('foo'123);
$pp->start();
?>

# We can retrieve bound values through CGI interface.
use strict;
use warnings;
use CGI;
our $q = new CGI();
print $q->param('foo'), "\n";
print $q->param('bar'), "\n";

<?php
$pp
->end();
// bind value(b)
$pp->bind('bar''ABC DEF GHI');

$pp->descriptors = array(
    
=> array('pipe''w'),
);
$pp->popen();

$output fread($pp->pipes[1], 8192);
echo 
$output PHP_EOL;
fclose($pp->pipes[1]);

$pp->pclose();

Reporting Bugs, Requests, Patches

You can report bugs, feature requests, and patches from Xhwlay's source forge tracker systems.
See http://sourceforge.net/projects/xhwlay/.
NOTE: Select "Pseudo_Block" from "Category" when you send.

Hava a funny PHP programming !!