Menu
CoddyTech

Modules and first run

Lesson 1 of 48 in Coddy's PHP for Luau Developers course.

Luau is embedded in a host that supplies entry and module conventions; this CLI supports relative require paths. PHP executes an entry file and loads declarations with require_once. Use __DIR__ for PHP dependencies and keep reusable modules free of top-level output.

PHP CLI files start with an opening PHP tag. Keep reusable declarations in modules and output in the entry script. require_once loads a file only once; __DIR__ anchors its path to the current file instead of the working directory. These courses use PHP 8.3 syntax and standard CLI input, not a web framework. Strict scalar calls are requested with declare(strict_types=1) in the caller file.

Luau program

print("hello CLI")

Source output:

hello CLI

PHP program

demo.php

<?php
declare(strict_types=1);
echo "hello CLI\n";

PHP output:

hello CLI
challenge icon

Challenge

Easy

Run unchanged. The main script loads Functions.php relative to its own directory and prints PHP is ready.

The supplied main script reads one JSON value from standard input, checks the named public APIs, and prints the result. Implement the module declarations without printing; do not replace the launcher or read input from a module. Input satisfies the stated types and bounds.

Edit Functions.php. main.php is the locked entry file. Dependencies use require_once __DIR__ with a relative filename.

Try it yourself

<?php
declare(strict_types=1);
require_once __DIR__."/Functions.php";
function ensure(bool $ok,string $message):void{if(!$ok)throw new RuntimeException("API: ".$message);}

$input=json_decode(trim(stream_get_contents(STDIN)),true,512,JSON_THROW_ON_ERROR);
ensure(welcome()==="PHP is ready","welcome");
echo welcome(),"\n";

All lessons in PHP for Luau Developers

Practice on your own: Online PHP compiler