PHPackages                             swthemathwiz/php-perl - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. swthemathwiz/php-perl

ActivePhp-ext

swthemathwiz/php-perl
=====================

PHP extension for running Perl code from PHP

v1.21.5(today)58↑2900%1The PHP License, version 3.0CPHP &gt;=7.4CI passing

Since Aug 14Pushed today1 watchersCompare

[ Source](https://github.com/swthemathwiz/php-perl)[ Packagist](https://packagist.org/packages/swthemathwiz/php-perl)[ RSS](/packages/swthemathwiz-php-perl/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

PHP Perl Extension (Updated for PHP 7 and PHP 8)
================================================

[](#php-perl-extension-updated-for-php-7-and-php-8)

What is the PHP Perl Extension?
===============================

[](#what-is-the-php-perl-extension)

This extension allows embedding a Perl interpreter into PHP 7+, enabling you to:

- Execute Perl files
- Evaluate Perl code
- Access values of Perl variables
- Call Perl subroutines
- Instantiate and manipulate Perl objects

About the Updates
=================

[](#about-the-updates)

I have updated version 1.0.1 of the php-perl extension source (built for PHP 5) to support PHP 7+. The source has been modified extensively. I started numbering the new versions from 1.20.0. The updates have never been tested on any OS other than Linux, so your mileage may vary on other operating systems.

Except as noted, the syntax and semantics have not changed, and the limitations of the PHP 5 version are still present.

The primary changes were:

- Adapted to the newer PHP object model.
- Modified the use of binary hashes (no longer supported).
- Deleted the older tasking model code.
- Made general changes for the PHP 5-to-7 transition.
- Updated miscellaneous code (4+ years of API changes).
- Modified various tests, primarily because `var_dump` does not sort hashes consistently. Some tests use Perl's `Data::Dumper` to get around the lack of consistent hash sorting in `var_dump`.
- Added a few tests.
- Converted about 4 tests to XFAIL (known limitations).
- N.B.: The code is no longer compatible with PHP 5.

The original source was released under the PHP v3.0 license, and my modifications are released under the same license.

Requirements
============

[](#requirements)

- PHP 7.4 or later; PHP 8.x with additional caveats
- Perl 5.8.0 or later with the `ExtUtils::Embed` module

Quick Install
=============

[](#quick-install)

Step 1. Compile this extension. `PHP_PREFIX` and `PERL_PREFIX` must point to valid PHP and Perl installation prefixes:

```
    export PHP_PREFIX="/usr"
    export PERL_PREFIX="/usr"
    $PHP_PREFIX/bin/phpize
    ./configure --with-perl=$PERL_PREFIX --with-php-config=$PHP_PREFIX/bin/php-config
    make
```

Step 2. Install the extension (this step can require root privileges):

```
    make install
```

Step 3. Add the Perl extension to your `php.ini` (this step can require root privileges):

```
    extension=perl
```

Windows Installation Notes
==========================

[](#windows-installation-notes)

PHP only supports the MSVC toolchain and does not generally include development support (headers and libraries). So, prerequisites are:

- Obtain (or build) a Perl version built with MSVC (an officially supported configuration). Most versions of Perl on Windows are built using the MinGW toolchain.
- Install the PHP Development Pack from [PHP](https://windows.php.net/downloads/).
- Install [MSYS2](https://www.msys2.org/) to augment your build toolchain to include tools such as bison, sed, and re2c.

Step 1. Compile this extension. `PHP_PREFIX` and `PERL_PREFIX` must point to valid PHP and Perl installation prefixes:

```
    SET PERL_PREFIX=C:\perl
    SET PHP_PREFIX=C:\php
    "%PHP_PREFIX%\phpize.bat"
    .\configure.bat --with-perl="%PERL_PREFIX%" --with-prefix="%PHP_PREFIX%"
    nmake
```

Step 2. Copy `php_perl.dll` (from `Release`) to the PHP extension directory.

Step 3. Add the Perl extension to your `php.ini`:

```
    extension=perl
```

PHP API
=======

[](#php-api)

`new Perl()`
------------

[](#new-perl)

Creates a Perl interpreter. It allows:

- Reading and modifying Perl variables
- Calling Perl functions
- Evaluating Perl code
- Loading and executing external Perl files

Examples:

```
    $perl = new Perl();
    var_dump($perl->x);         // print scalar Perl variable - $x
    var_dump($perl->scalar->x); //   explicit alternative - $x
    var_dump($perl->array->x);  // print array Perl variable - @x
    var_dump($perl->hash->x);   // print hash Perl variable - %x
    $perl->func();              // call Perl function 'func' in void context
    $x = $perl->func();         // call Perl function 'func' in scalar context
    $y = $perl->array->func();  // call Perl function 'func' in array context
    $y = $perl->hash->func();   // call Perl function 'func' in hash context

    $perl->eval('use Digest::MD5');
    echo $perl->{'Digest::MD5::md5_hex'}('Hello');
```

`$perl->eval($perl_code)`
-------------------------

[](#perl-evalperl_code)

Evaluates Perl code and returns the result. If the Perl code is invalid, the method will throw a PHP exception.

Examples:

```
    $perl = new Perl();
    $perl->eval('require "test.pl";');
    echo $perl->eval($x.'+'.$y.';');
    $perl->eval('$z='.$x.'+'.$y.';');
```

By default, Perl code is evaluated in scalar context, but it can be evaluated in array or hash contexts too.

Examples:

```
    $perl = new Perl();
    $perl->eval('("a","b","c")');                  // eval in void context
    var_dump($perl->eval('("a","b","c")'));        // eval in scalar context
    var_dump($perl->array->eval('("a","b","c")')); // eval in array context
    var_dump($perl->hash->eval('("a","b","c")'));  // eval in hash context
```

`$perl->require($perl_file_name)`
---------------------------------

[](#perl-requireperl_file_name)

Loads and executes a Perl file. It does not return any value. If the required Perl file does not exist or is invalid, the method will throw a PHP exception.

Examples:

```
    $perl = new Perl();
    $perl->require('test.pl');
```

`new Perl($perl_class_name[, $constructor = "new"[, ...]])`
-----------------------------------------------------------

[](#new-perlperl_class_name-constructor--new-)

Creates an instance of a Perl class by calling a specified constructor (defaulting to "new" if omitted). Additional parameters are passed to Perl's constructor. The created object allows:

- Reading and modifying object properties
- Calling methods
- Cloning

Examples:

```
    $x = new Perl("Test");
    $y = new Perl("Test","copy",$x);
    $z = clone $y;
    echo $z->property;
    echo $z->method(1,2,3);
```

Methods can be called in array or hash contexts in the same way as Perl functions, but all properties are accessible directly (without array or hash modifiers).

Examples:

```
    $x = new Perl("Test");
    $x->f();                  // call method "f" in void context
    var_dump($x->f());        // call method "f" in scalar context
    var_dump($x->array->f()); // call method "f" in array context
    var_dump($x->hash->f());  // call method "f" in hash context
```

Known Bugs and Limitations
==========================

[](#known-bugs-and-limitations)

- Perl objects are passed between Perl and PHP by reference; all other data types (including arrays and hashes) are passed by value. Therefore, modifying Perl's arrays and hashes in PHP does not change the corresponding Perl variables.

```
        $x = $perl->array->x;
        $x[0] = 1; // Perl's array @x still unmodified

        // However, you can use PHP references to achieve this:

        $y = &$perl->array->y;
        $y[0] = 1; // Modifies Perl's array @y
```

- The extension cannot call internal Perl functions (`print`, `die`, ...).
- In PHP 8.x, references to Perl variables are not properly handled:

```
        $perl->y = 1;
        $x = &$perl->y;
        $x = 2;
        var_dump( $perl->y ); // Should be int(2), but is int(1)
```

Testing
=======

[](#testing)

The status of the most recent testing follows:

OSPHP VersionPerl VersionStatusUbuntu 20.04 LTS7.4.265.30.0All PassedUbuntu 20.04 LTS8.0.135.30.0PHP 8.x References to Perl variables not usableUbuntu 20.04 LTS8.1.05.30.0PHP 8.x References to Perl variables not usableUbuntu 22.04 LTS8.1.25.34.0PHP 8.x References to Perl variables not usableUbuntu 24.04 LTS8.3.65.38.2PHP 8.x References to Perl variables not usableUbuntu 26.04 LTS8.5.45.40.1PHP 8.x References to Perl variables not usableFedora 347.4.275.32.1All PassedFedora 358.0.135.34.0PHP 8.x References to Perl variables not usableFedora 388.2.85.36.1PHP 8.x References to Perl variables not usableFedora 398.2.135.38.2PHP 8.x References to Perl variables not usableFedora 408.3.125.38.2PHP 8.x References to Perl variables not usableFedora 428.4.215.40.4PHP 8.x References to Perl variables not usableFedora 438.4.245.42.3PHP 8.x References to Perl variables not usableFedora 448.5.95.42.3PHP 8.x References to Perl variables not usableThe original extension was tested on Red Hat Linux 9.0 with PHP 5.0.0RC2-dev (non-ZTS build) and Perl 5.8.0 (installed from RPM), and on Windows 2000 with PHP 5.0.0RC2-dev (ZTS build) and Perl 5.8.0.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/23059576?v=4)[swthemathwiz](/maintainers/swthemathwiz)[@swthemathwiz](https://github.com/swthemathwiz)

---

Top Contributors

[![swthemathwiz](https://avatars.githubusercontent.com/u/23059576?v=4)](https://github.com/swthemathwiz "swthemathwiz (202 commits)")

---

Tags

languagesextensionperl

### Embed Badge

![Health badge](/badges/swthemathwiz-php-perl/health.svg)

```
[![Health](https://phpackages.com/badges/swthemathwiz-php-perl/health.svg)](https://phpackages.com/packages/swthemathwiz-php-perl)
```

###  Alternatives

[bnomei/autoloader-for-kirby

Helper to automatically load various Kirby extensions in a plugin

185.8k2](/packages/bnomei-autoloader-for-kirby)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
