NAME
PHP - embedded PHP interpreter
DESCRIPTION
The module makes it possible to execute PHP code, call PHP functions and methods, manipulating PHP arrays, and create PHP objects.
SYNOPSIS
use PHP;
# 1 - general use
# 1.1
# evaluate arbitrary PHP code; exception is thrown
# and can be catched via standard eval{}/$@ block
PHP::eval(<<EVAL);
function print_val(\$arr,\$val) {
echo \$arr[\$val];
}
class TestClass {
function TestClass () {}
function method(\$val) { return \$val + 1; }
};
EVAL
# catch output of PHP code
PHP::options( stdout => sub {
print "PHP says: $_[0]\n";
});
PHP::eval('echo 42;');
# 2 - arrays
# create a php array
my $array = PHP::array();
# tie it either to an array or a hash
my ( @array, %hash);
$array-> tie(\%hash);
$array-> tie(\@array);
# access array content
$array[1] = 42;
$hash{2} = 43;
# pass arrays to function
# Note - function name is not known by perl in advance, and
# is called via DUTOLOAD
PHP::print_val($a, 1);
PHP::print_val($a, 2);
# 3 - classes
my $TestClass = PHP::Object-> new('TestClass');
print $TestClass-> method(42), "\n";
API
- call FUNCTION ...
-
Calls PHP function with list of parameters. Returns exactly one value.
- include, include_once, require, require_once
-
Shortcuts to the identical PHP constructs.
- array
-
Returns a handle to a newly created PHP array of type
PHP::Array
. The handle can be later tied with perl hashes or arrays viatie
call. - PHP::Array::tie $array_handle, $tie_to
-
Ties existing handle to a PHP array to either a perl hash or a perl array. The tied hash or array can be used to access PHP pseudo_hash values indexed either by string or integer value.
- PHP::Object::new $class_name
-
Instantiates a PHP object of PHP class $class_name and returns a handle to it. The methods of the PHP class can be called directly via the handle:
my $obj = PHP::Object-> new();
- PHP::options
-
Contains set of internal options. If called without parameters, returns the names of the options. If called with a single parameter, return the associated value. If called with two parameters, replaces the associated value.
DEBUGGING
Environment variable P5PHPDEBUG
is set to 1, turns the debug mode on. The same effect can be achieved programmatically by calling
PHP::options( debug => 1);
INSTALLATION
The module uses php-embed SAPI extension to interoprate with PHP interpreter. That means php must be configured with '--enable-embed' parameters prior to using the module.
The sub dl_load_flags { 0x01 }
code in PHP.pm is required for PHP to load correctly its extenstions. If your platform does RTLD_GLOBAL by default and croaks upon this line, it is safe to remove the line.
SEE ALSO
Using Perl code from PHP: http://www.zend.com/php5/articles/php5-perl.php
COPYRIGHT
Copyright (c) 2005 catpipe Systems ApS. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
Dmitry Karasik <dmitry@karasik.eu.org>