Code Monkey home page Code Monkey logo

php-constant's Introduction

php-constant

Scrutinizer Code Quality

Dynamic constants at runtime with rust-like lifetime for PHP 7

##example

<?php
use function Dgame\Constant\get;
use function Dgame\Constant\let;

print '<pre>';

function foo()
{
    let('created')->be(time());
    print __METHOD__ . ' -- created: ' . get('created') . PHP_EOL;
//    let('created')->be(time());
}

foo();
foo();

let('created')->be(time());
print 'Global -- created: ' . get('created') . PHP_EOL;

function bar()
{
    let('result')->be(5 * 5);
    print __METHOD__ . ' -- result ' . get('result') . PHP_EOL;
}

bar();

//print 'Global -- created: ' . get('result') . PHP_EOL;

function quatz()
{
    let('result')->be(6 * 6);
    print __METHOD__ . ' -- result: ' . get('result') . PHP_EOL;

    foo();
    bar();

    print __METHOD__ . ' -- result: ' . get('result') . PHP_EOL;
}

quatz();

let('foo')->be('bar');

print 'Global -- foo: ' . get('foo') . PHP_EOL;

function test()
{
    let('zip_filename')->be('foo.zip');

    print __METHOD__ . ' -- zip_filename: ' . get('zip_filename') . PHP_EOL;

    for ($i = 0; $i < 1; $i++) {
        let('img_filename')->be('bar.png');

        print __METHOD__ . ' -- img_filename: ' . get('img_filename') . PHP_EOL;
    }

    print __METHOD__ . ' -- img_filename: ' . get('img_filename') . PHP_EOL;
    print __METHOD__ . ' -- zip_filename: ' . get('zip_filename') . PHP_EOL;
}

test();

let('fac')->be(function(int $in) {
    $out = 1;

    // Only if $in is >= 2
    for ($i = 2; $i <= $in; $i++) {
        $out *= $i;
    }

    return $out;
});

print 'Global -- fac: ' . get('fac')(6) . PHP_EOL;

php-constant's People

Contributors

dgame avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.