Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/ext-hello

bm-ext MIT

Demo extension: bm_hello() only, no dependencies.

needs no platform HAL

ext-hello · Recipe

Check that a package is built in

Require ext-hello, flash, and read one line on the serial console: the fastest check that your project builds the packages it requires.

Before wiring hardware, make sure the package pipeline works: a package you require ends up in the firmware and its functions are callable from your script. ext-hello needs nothing else, so if it does not show up, the problem is the project setup, not a missing provider. Remove it from the project afterwards.

Goal

Print the greeting from bm_hello() on the serial console, and list the extensions the firmware actually contains.

The steps

  1. Require the package

    From the project: composer require php-baremetal/ext-hello.

  2. Build and flash

    phpbm flash, as for any change to the project's packages.

  3. Run the script and open the console

    Put the code below in project-src/index.php, then phpbm monitor.

The code

php project-src/index.php
<?php
echo extension_loaded('hello') ? bm_hello() : 'ext-hello missing', "\n";

// Every extension compiled into this firmware.
echo implode(', ', get_loaded_extensions()), "\n";

function loop(int $tick): void
{
    delay(1000);
}

Expected output; the extension list depends on what your project requires, and hello must be in it:

text serial console
hello from ext-hello package
Core, date, ..., hello, ...

Related