PHP code example of jdwx / strict

1. Go to this page and download the library: Download jdwx/strict library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdwx / strict example snippets



if ( ! preg_match( '/test/', $string ) ) {
    echo "It didn't match!";
} else {
    echo "It matched!";
}

if ( ! OK::preg_match( '/test/', $string ) ) {
    echo "It didn't match!";
} else {
    echo "It matched!";
}

$contents = @file_get_contents( '/some/file' );
if ( ! is_string( $contents ) ) {
    throw new RuntimeException( 'file read failed!' );
}

$contents = OK::file_get_contents( '/some/file' );

i_

assert( is_string( $string_or_null ) );
i_

assert( is_string( $this->string_or_null ) );
i_

$string = $this->string_or_null;
assert( is_string( $string) );
i_

i_

$string = TypeIs::string( $string_or_null );
i_ire_a_string( $string );


declare( strict_types = 1 );

/** @param array<string, string> */
function do_a_thing( array $r ) : void {
    foreach ( $r as $k => $v ) {
        i_

declare( strict_types = 1 );

/** @param array<string, string> */
function do_a_thing( array $r ) : void {
    foreach ( Iter::mapString( $r ) as $k => $v ) {
        i_


/** @param list<string>|string $targets */
function do_things( array|string $targets ) : void {
    if ( ! is_array( $targets ) ) {
        $targets = [ $targets ];
    }
    // ...
    foreach ( $targets as $target ) {
        do_a_thing( $target );
    }
}

/** @param list<string>|string $targets */
function do_things( array|string $targets ) : void {
    foreach ( Convert::listOrString( $targets ) as $target ) {
        do_a_thing( $target );
    }
}