PHPackages                             php-script/php-script - 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. php-script/php-script

ActiveLibrary

php-script/php-script
=====================

php script is a script language powered by backend php with editing in the browser for supporting ui-driven php applications.

v1.0.3(5mo ago)00[4 PRs](https://github.com/php-script/php-script/pulls)MITPHPPHP ^8.4.0CI passing

Since Nov 11Pushed 1mo agoCompare

[ Source](https://github.com/php-script/php-script)[ Packagist](https://packagist.org/packages/php-script/php-script)[ Fund](https://www.buymeacoffee.com/robertkummer)[ Fund](https://www.paypal.me/rok)[ RSS](/packages/php-script-php-script/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (10)Used By (0)

PHP Script
==========

[](#php-script)

 [ ![PHP Script](/art/php-script-logo.png) ](https://github.com/php-script/php-script)

 [![GitHub Workflow Status (master)](https://github.com/php-script/php-script/actions/workflows/tests.yml/badge.svg)](https://github.com/php-script/php-script/actions) [![Total Downloads](https://camo.githubusercontent.com/76e331c139cf339ea5111553ef352eb8de5300e48c866d06c2c5b6aca51df6b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d7363726970742f7068702d736372697074)](https://packagist.org/packages/php-script/php-script) [![Latest Version](https://camo.githubusercontent.com/7a356a2110af14317500856f91ab4f3c8155be0138d1c607f5a374a8dcc6933d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d7363726970742f7068702d736372697074)](https://packagist.org/packages/php-script/php-script) [![License](https://camo.githubusercontent.com/f00f11cca82a7425a57f2f78963382d6bcca910615759dbf6038ef79b9d89a1b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7068702d7363726970742f7068702d736372697074)](https://packagist.org/packages/php-script/php-script)

---

PHP Script is a scripting language that allows end-users to customize and extend your PHP-powered backend with the simplicity of JavaScript. It provides a secure and controlled environment to execute user-generated scripts without the need for a separate Node.js service.

Features
--------

[](#features)

- **Easy to Use:** The syntax is inspired by JavaScript, making it familiar to a wide range of developers.
- **Secure:** The engine provides a sandboxed environment, giving you full control over the exposed functions and data.
- **Flexible:** You can expose any PHP function or variable to the script, allowing for powerful customizations.
- **Lightweight:** The package is designed to be lightweight and has minimal dependencies.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require php-script/php-script
```

Usage
-----

[](#usage)

### 1. Setting up the Engine

[](#1-setting-up-the-engine)

First, you need to create an instance of the `Engine` and expose the necessary data and functions to the script.

```
use PhpScript\Core\Engine;

class LoginStats
{
    public function count(): int
    {
        return 42;
    }
}

class User
{
    public string $name = "Administrator";
    public LoginStats $logins;

    public function __construct()
    {
        $this->logins = new LoginStats();
    }

    public function hasPermission(string $perm): bool
    {
        return $perm === 'admin';
    }
}

// Setting up the PHP Script engine
$engine = new Engine();
$engine->set('user', new User());
$engine->set('app_version', '1.2.3');
$engine->set('users_list', ['Alice', 'Bob', 'Charlie']);

// Optionally, set an execution time limit to prevent infinite loops
$engine->setExecutionTimeLimit(5); // Script will time out after 5 seconds
```

### 2. Writing a PHP Script

[](#2-writing-a-php-script)

Now, you can write a script that interacts with the exposed data and functions.

```
// This is a line comment
echo 'Hello ' + user.name // String concatenation and object property access

// Calling a method
totalLogins = user.logins.count();
echo 'Logins: ' + totalLogins;

// Working with variables
var1 = 10;
var2 = var1 * 2 + totalLogins;
echo 'Sum: ' + var2;

// Conditional statements
if (var2 > 50) {
    echo 'var2 is greater than 50!';
}

// Looping through an array
echo 'Users list:';
foreach (users_list as u) {
    echo '- ' + u;
}

// Calling a method with an argument
if (user.hasPermission('admin')) {
    echo 'Access granted!';
}

// Accessing a global variable
echo 'App Version: ' + app_version;
```

### 3. Executing the Script

[](#3-executing-the-script)

Finally, you can execute the script using the `execute` method of the `Engine`.

```
try {
    echo $engine->execute($script);
} catch (Exception $exception) {
    echo $exception->getMessage();
}
```

This will produce the following output:

```
Hello Administrator
Logins: 42
Sum: 62
var2 is greater than 50!
Users list:
- Alice
- Bob
- Charlie
Access granted!
App Version: 1.2.3

```

PHP Script Language Reference
-----------------------------

[](#php-script-language-reference)

[![Deploy Jekyll site to Pages](https://github.com/php-script/php-script/actions/workflows/pages.yml/badge.svg)](https://github.com/php-script/php-script/actions/workflows/pages.yml)

Please take a look into the language reference [online](https://php-script.github.io/php-script/).

Features
--------

[](#features-1)

- Abstract Syntax Tree (AST) is in use
- we render PHP from AST
- we can render PHP Script from AST
- robust error handling with a pointer to the root cause in the PHP Script
- 100% code coverage
- Whitelist implementation for allowing function calls
- Playground
    - use `make playground` and open  in your browser
    - with a Monaco prepared editor
    - using PhpScriptRenderer as linter
- Monarch language definition for the keywords and dynamic code suggestion for provided context
    - Monaco-based editors can learn the language and provide code completion (Monaco, vscode)

TODO
----

[](#todo)

- render Mermaid.js Flowchart from AST
- Provide a Monaco editor component for vanilla JavaScript
- Provide a Monaco editor component for Vue.js
- Provide a Monaco editor component for React.js

Contribution
------------

[](#contribution)

1. Create a branch from main
2. do your stuff
3. document your stuff here
4. call `composer lint` until no errors
5. call `composer refactor` until no errors
6. call `composer lint` again until no errors
7. call `composer test` until no errors
8. commit and push your changes and open a PR

SDD - Spec-Driven-Development
-----------------------------

[](#sdd---spec-driven-development)

The spec-driven development is supported. All base files are generated.

The flow:

- /constitution - already DONE
- for each new feature:
    - /specify
        - optional: /clarify
    - /plan
    - /tasks
    - /implement
- optional: at any time /analyze to check your specs
-

Local development
-----------------

[](#local-development)

🧹 Keep a modern codebase with **Pint**:

```
composer lint
```

✅ Run refactors using **Rector**

```
composer refactor
```

⚗️ Run static analysis using **PHPStan**:

```
composer test:types
```

✅ Run unit tests using **PEST**

```
composer test:unit
```

🚀 Run the entire test suite:

```
composer test
```

**PHP Script** was created by **[Robert Kummer](https://robert-kummer.de)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.8% 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

Every ~7 days

Total

4

Last Release

166d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4946056?v=4)[Robert Kummer](/maintainers/rokde)[@rokde](https://github.com/rokde)

---

Top Contributors

[![rokde](https://avatars.githubusercontent.com/u/4946056?v=4)](https://github.com/rokde "rokde (220 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")[![google-labs-jules[bot]](https://avatars.githubusercontent.com/in/842251?v=4)](https://github.com/google-labs-jules[bot] "google-labs-jules[bot] (2 commits)")

---

Tags

phplanguagescriptphp script

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[felixfbecker/language-server-protocol

PHP classes for the Language Server Protocol

22476.7M6](/packages/felixfbecker-language-server-protocol)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)[eftec/minilang

A mini scripting language for php

113.2k2](/packages/eftec-minilang)

PHPackages © 2026

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