{"id":16570411,"url":"https://github.com/blyxxyz/python-php-bridge","last_synced_at":"2026-03-06T03:32:30.285Z","repository":{"id":56951068,"uuid":"130643862","full_name":"blyxxyz/Python-PHP-Bridge","owner":"blyxxyz","description":"Import PHP code into Python","archived":false,"fork":false,"pushed_at":"2020-04-17T17:59:34.000Z","size":105,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T04:51:15.253Z","etag":null,"topics":["bridge","php","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blyxxyz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-23T05:20:48.000Z","updated_at":"2025-01-07T10:29:44.000Z","dependencies_parsed_at":"2022-08-21T03:40:16.100Z","dependency_job_id":null,"html_url":"https://github.com/blyxxyz/Python-PHP-Bridge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/blyxxyz/Python-PHP-Bridge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blyxxyz%2FPython-PHP-Bridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blyxxyz%2FPython-PHP-Bridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blyxxyz%2FPython-PHP-Bridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blyxxyz%2FPython-PHP-Bridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blyxxyz","download_url":"https://codeload.github.com/blyxxyz/Python-PHP-Bridge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blyxxyz%2FPython-PHP-Bridge/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265529118,"owners_count":23782824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bridge","php","python"],"created_at":"2024-10-11T21:18:44.088Z","updated_at":"2026-03-06T03:32:30.236Z","avatar_url":"https://github.com/blyxxyz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a Python module for running PHP programs. It lets you import PHP functions, classes, objects, constants and variables to work just like regular Python versions.\n\n# Examples\n\nYou can call functions:\n```pycon\n\u003e\u003e\u003e from phpbridge import php\n\u003e\u003e\u003e php.array_reverse(['foo', 'bar', 'baz'])\nArray.list(['baz', 'bar', 'foo'])\n\u003e\u003e\u003e php.echo(\"foo\\n\")\nfoo\n\u003e\u003e\u003e php.getimagesize(\"http://php.net/images/logos/new-php-logo.png\")\nArray([('0', 200), ('1', 106), ('2', 3), ('3', 'width=\"200\" height=\"106\"'), ('bits', 8), ('mime', 'image/png')])\n```\n\nYou can create and use objects:\n```pycon\n\u003e\u003e\u003e php.DateTime\n\u003cPHP class 'DateTime'\u003e\n\u003e\u003e\u003e date = php.DateTime()\n\u003e\u003e\u003e print(date)\n\u003cDateTime PHP object (date='2018-05-03 22:59:15.114277', timezone_type=3, timezone='Europe/Berlin')\u003e\n\u003e\u003e\u003e date.getOffset()\n7200\n\u003e\u003e\u003e php.ArrayAccess\n\u003cPHP interface 'ArrayAccess'\u003e\n\u003e\u003e\u003e issubclass(php.ArrayObject, php.ArrayAccess)\nTrue\n```\n\nYou can use keyword arguments, even though PHP doesn't support them:\n```pycon\n\u003e\u003e\u003e date.setDate(year=1900, day=20, month=10)\n\u003cDateTime PHP object (date='1900-10-20 22:59:15.114277', timezone_type=3, timezone='Europe/Berlin')\u003e\n```\n\nYou can loop over iterators and traversables:\n```pycon\n\u003e\u003e\u003e for path, file in php.RecursiveIteratorIterator(php.RecursiveDirectoryIterator('.git/logs')):\n...     print(\"{}: {}\".format(path, file.getSize()))\n...\n.git/logs/.: 16\n.git/logs/..: 144\n.git/logs/HEAD: 2461\n[...]\n```\n\nYou can get help:\n```pycon\n\u003e\u003e\u003e help(php.echo)\nHelp on function echo:\n\necho(arg1, *rest)\n    Output one or more strings.\n\n    @param mixed $arg1\n    @param mixed ...$rest\n\n    @return void\n```\n\nYou can import namespaces as modules:\n```pycon\n\u003e\u003e\u003e from phpbridge.php.blyxxyz.PythonServer import NonFunctionProxy\n\u003e\u003e\u003e help(NonFunctionProxy)\nHelp on class blyxxyz\\PythonServer\\NonFunctionProxy in module phpbridge.php.blyxxyz.PythonServer:\n\nclass blyxxyz\\PythonServer\\NonFunctionProxy(phpbridge.objects.PHPObject)\n |  Provide function-like language constructs as static methods.\n |\n |  `isset` and `empty` are not provided because it's impossible for a real\n |  function to check whether its argument is defined.\n |\n |  Method resolution order:\n |      blyxxyz\\PythonServer\\NonFunctionProxy\n |      phpbridge.objects.PHPObject\n |      builtins.object\n |\n |  Class methods defined here:\n |\n |  array(val) -\u003e dict from phpbridge.objects.PHPClass\n |      Cast a value to an array.\n |\n |      @param mixed $val\n |\n |      @return array\n[...]\n```\n\nYou can index, and get lengths:\n```pycon\n\u003e\u003e\u003e arr = php.ArrayObject(['foo', 'bar', 'baz'])\n\u003e\u003e\u003e arr[10] = 'foobar'\n\u003e\u003e\u003e len(arr)\n4\n```\n\nYou can work with PHP's exceptions:\n```pycon\n\u003e\u003e\u003e try:\n...     php.get_resource_type(3)\n... except php.TypeError as e:\n...     print(e.getMessage())\n...\nget_resource_type() expects parameter 1 to be resource, integer given\n```\n\n# Features\n  * Using PHP functions\n    * Keyword arguments are supported and translated based on the signature\n    * Docblocks are also converted, so `help` is informative\n  * Using PHP classes like Python classes\n    * Methods and constants are defined right away based on the PHP class\n    * Docblocks are treated like docstrings, so `help` works and is informative\n    * The original inheritance structure is copied\n    * Default properties become Python properties with documentation\n    * Other properties are accessed on the fly as a fallback for attribute access\n  * Creating and using objects\n  * Importing namespaces as modules\n  * Getting and setting constants\n  * Getting and setting global variables\n  * Translating exceptions so they can be treated as both Python exceptions and PHP objects\n  * Tab completion in the interpreter\n  * Python-like reprs for PHP objects, with information like var_dump in a more compact form\n\n# Caveats\n  * On Windows, stdin and stderr are used to communicate, so PHP can't read input and if it writes to stderr the connection is lost\n  * You can only pass basic Python objects into PHP\n  * Namespaces can shadow names in an unintuitive way\n  * Because PHP only has one kind of array, its arrays are translated to a special kind of ordered dictionary\n\n# Name conflicts\nSome PHP packages use the same name both for a class and a namespace. As an example, take `nikic/PHP-Parser`.\n\n`PhpParser\\Node` is a class, but `PhpParser\\Node\\Param` is also a class. This means `phpbridge.php.PhpParser.Node` becomes ambiguous - it could either refer to the `Node` class, or the namespace of the `Param` class.\n\nIn case of such a conflict, the class is preferred over the namespace. To get `Param`, a `from` import has to be used:\n```pycon\n\u003e\u003e\u003e php.require('vendor/autoload.php')\n\u003cComposer.Autoload.ClassLoader PHP object (prefixLengthsPsr4=[...: (4)], ...\u003e\n\u003e\u003e\u003e import phpbridge.php.PhpParser.Node as Node           # Not the namespace!\n\u003e\u003e\u003e Node\n\u003cPHP interface 'PhpParser\\Node'\u003e\n\u003e\u003e\u003e from phpbridge.php.PhpParser.Node import Param        # The class we want\n\u003e\u003e\u003e Param\n\u003cPHP class 'PhpParser\\Node\\Param'\u003e\n\u003e\u003e\u003e import phpbridge.php.PhpParser.Node.Param as Param    # Doesn't work\nTraceback (most recent call last):\n  File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\nAttributeError: type object 'PhpParser\\Node' has no attribute 'Param'\n```\n\nIf there are no conflicts, things work as expected:\n```pycon\n\u003e\u003e\u003e from phpbridge.php.blyxxyz.PythonServer import Commands\n\u003e\u003e\u003e Commands\n\u003cPHP class 'blyxxyz\\PythonServer\\Commands'\u003e\n\u003e\u003e\u003e import phpbridge.php.blyxxyz.PythonServer as PythonServer\n\u003e\u003e\u003e PythonServer\n\u003cPHP namespace 'blyxxyz\\PythonServer'\u003e\n\u003e\u003e\u003e PythonServer.Commands\n\u003cPHP class 'blyxxyz\\PythonServer\\Commands'\u003e\n```\n\n# Installing\n\n```\npip3 install phpbridge\n```\n\nThe only dependencies are PHP 7.0+, Python 3.5+, ext-json, ext-reflection and ext-mbstring. Composer can be used to install development tools and set up autoloading, but it's not required.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblyxxyz%2Fpython-php-bridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblyxxyz%2Fpython-php-bridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblyxxyz%2Fpython-php-bridge/lists"}