MicrofyClass.php

Micro utility functions for everyday PHP tasks. Minimal helpers for maximum flow

MicrofyClass.php

Minimal utility helpers for everyday PHP tasks (object-oriented version)


🧰 What is it?

MicrofyClass.php is the object-oriented version of microfy.php β€” a minimalist utility class packed with static helper methods to simplify everyday PHP development.

It brings the same no-bloat, no-dependency philosophy β€” now in a class-based format β€” offering tools for request handling, debugging, logging, HTML snippets, database access, and more.

Forget frameworks when all you need is power and speed β€” Microfy is your coding pocketknife.


πŸ’‘ Why use it?


✨ Features


πŸ“Œ When to Use MicrofyClass.php

Use MicrofyClass.php when:


πŸ›  Bonus: Procedural Aliases

Want the simplicity of pp($data) or dbAll(...) in your OOP project?

Just include microfy_aliases.php to use short, procedural-style aliases for all Microfy:: methods β€” no need to prefix everything manually.

require_once 'MicrofyClass.php';
require_once 'microfy_aliases.php';

pp(['quick', 'debug']); // works alongside Microfy::pp(...)

πŸš€ Usage Examples

// Set example input values
$_GET = [
    'name' => 'Alice',
    'city' => 'Wonderland'
];
$_POST = [
    'age' => '30'
];

🧾 Input Handling

$name = get('name', 'Guest');
$age  = post('age', 'unknown');
$city = request('city', 'Nowhere');
p("Hello, $name ($age), from $city.");
p("val($_GET, 'name', 'NoName'));

Hello, Alice (30), from Wonderland.

val($_GET, 'name'): Alice

pp([
    'getVars'  => getVars(['name', 'city']),
    'postVars' => postVars(['age']),
    'reqVars'  => reqVars(['name', 'city', 'age'])
]);
Array
(
    [getVars] => Array
        (
            [name] => Alice
            [city] => Wonderland
        )

    [postVars] => Array
        (
            [age] => 30
        )

    [reqVars] => Array
        (
            [name] => 
            [city] => 
            [age] => 
        )

)
injectGlobals(['name', 'city'], $_GET);
p("Injected Global: \$name = $name");

Injected Global: $name = Alice

extract(getVarsWithPrefix($_GET));
br($get_name);
br($$get_city);

Alice
Wonderland
$_POST['lang'] = 'en';
$_POST['theme'] = 'dark';
pp(loadInputs(['lang', 'theme'], $_POST));
Array
(
    [0] => en
    [1] => dark
)

πŸ—ƒοΈ Database (mocked connection)

echo htmlTable(dbAll($pdo, "SELECT id, username FROM users"));
idusername
1admin
2bob
pp(dbOne($pdo, "SELECT * FROM users WHERE id = 1"));
p("Total users: " . dbVal($pdo, "SELECT COUNT(*) FROM users"));
p("User #1 exists? " . (dbExists($pdo, 'users', 'id', 1) ? 'Yes' : 'No'));
} catch (Exception $e) {
    p("⚠️ DB Error: " . $e->getMessage());
}
Array
(
    [id] => 1
    [0] => 1
    [username] => admin
    [1] => admin
)

Total users: 2

User #1 exists? Yes

  h(2, 'πŸ” Pretty Debugging');
pp(['a' => 1, 'b' => [2, 3]]);
logPr(['user' => 'admin', 'ip' => '127.0.0.1']);
logVd(['server' => $_SERVER['SERVER_NAME'] ?? 'cli']);

πŸ” Pretty Debugging

Array
(
    [a] => 1
    [b] => Array
        (
            [0] => 2
            [1] => 3
        )

)

🧱 HTML Helpers

 h(2, '🧱 HTML Helpers');
h(1, 'Heading');
echo b("Bold") . ' ' . i("Italic") . ' ' . bi("Bold+Italic");
p("Paragraph");
echo small("Note");
echo div("Inside div", ['class' => 'box']);
section("Sectioned");
ul(['One', 'Two', 'Three']);
ulOpen();
li("First");
li("Second");
ulClose();
br();
hr();

Heading

Bold Italic Bold+Italic

Paragraph

Note
Inside div
Sectioned


πŸ‘¨β€πŸ’» Code Blocks

 code("Simple string");
codephp('<?php echo "Hello"; ?>');
codejson(json_encode(['key' => 'value']));
codesql('SELECT * FROM table');
Simple string
<?php echo "Hello"; ?>
{"key":"value"}
SELECT * FROM table

⏲️ Env / Utils

echo "Now: " . now();

Now: 2025-06-28 05:29:18
echo "ENV PATH: " . env('PATH', 'n/a') ;

ENV PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin
   echo "Slug: " . slugify("Hello World!") ;

Slug: hello-world
   echo "hsc(): ";
hsc('<b>XSS</b>');
hsc(): <b>XSS</b>
echo cStr('Some Text');  
echo cStr('Next');  
1. Some Text
2. Next

πŸ“¦ Response Wrappers

pp(jsonArray(['status' => 'ok', 'user' => $name]));
pp(jsonString('All good!'));
pp(jsonString('Something went wrong.', false));
{
    "status": "ok",
    "user": "Alice"
}
{
    "status": "ok",
    "msg": "All good!"
}
{
    "status": "fail",
    "msg": "Something went wrong."
}

🧩 Session Debug

session_start();
$_SESSION['token'] = 'abc123';
debugSession();
Session Name: PHPSESSID
Session ID:
$_SESSION:
Array
(
    [token] => abc123
)

πŸ”’ License

Released under the MIT License β€” © 2024–2025 itnb.com
This project is not affiliated with or endorsed by the PHP Foundation.
Use at your own risk β€” no warranties, no guarantees, just useful code.