PHP code example of netherphp / standards

1. Go to this page and download the library: Download netherphp/standards 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/ */

    

netherphp / standards example snippets




class Project {

	public function
	DoSomething(int $Count):
	void {
	/*//
	this method does something. we do not know exactly because this example
	is not important enough to fill with an implementation.
	//*/

		$Cur = 0;
		while($Cur < $Count) {
			// ...
		}

		return;
	}

}



class Project {

	public function
	DoSomething(int $Count):
	void {
	/*//
	this method does something. we do not know exactly because this example
	is not important enough to fill with an implementation.
	//*/ [...]
	}

}



$List = [];

while($Row = $Query->Next())
$List[] = $Row;




$List = [];
while($Row = $Query->Next()) {
	$Row->Cached = FALSE;
	$List[] = $Row;
}



preg_match(
	'/^https?:\/\/([^\/]+)/',
	$InputURL,
	$Matches
);



$Dataset = [
	'Something' => 1,
	'Else'      => 2,
	'MoreData'  => 3
];



$Dataset = [
	// these are the main system options.
	'Something' => 1,
	'Else'      => 2,
	'MoreData'  => 3,

	// mostly optional for whatever.
	'Four' => 4,
	'Five' => 5,
	'Six'  => 6
];



$Straight = 'some straight string without eval';
$Evaluated = "not {$Straight}";

$PageURL = sprintf(
	'%s://%s/%s',
	$RequestProtocol,
	$RequestDomain,
	$RequestPath
);



$String = "User: {$Name}";
$String = sprintf('User: %s',$Name);



$String = sprintf(
	'User: %s',
	$User->GetName()
);



$String = 'User: ' . $Name; // no.



namespace Nether\OneScript;
use ThirdParty1;
use ThirdParty2;

use ThirdParty3\Somespace\SomeClass;
use ThirdParty3\Filterspace\SomeInterface;

class Project
extends SomeClass
implements SomeInterface {
	// ...
}



namespace MyApp\Subspace;
use Nether;



class Project {

	public function
	SetSomething():
	void {
		// ...
		return;
	}

	static public function
	GetFromFile(string $Filename):
	string {
		// ...
		return $Contents;
	}

}



class Project {

	public function
	Search(array|object $Input=NULL):
	SearchResult {
	/*//
	@argv object Input
	@argv array Input
	//*/

		$Input = new Nether\Object($Input,[
			'Query' => NULL,
			'Page'  => 1,
			'Limit' => 25,
			'Owner' => NULL
		]);

		// ...

		return $Result;
	}

}



class Project {

	public function
	GetFileContents(string $Filename) {
	/*//
	@return ?StdClass
	given a filename return the object built from the contents of that file.
	//*/

		$Data = NULL;
		$Obj = NULL;
		$Error = NULL;

		try {
			$Data = $this->GetFileContents_ReadFile($Filename);
			$Obj = $this->GetFileContents_ParseData($Data);
		}

		catch(Exception $Error) {
			// log error or something.
			return NULL;
		}

		return $Obj;
	}

	protected function
	GetFileContents_ReadFile(string $Filename):
	string {
	/*//
	check that the file is readable from the filesystem.
	//*/

		if(!file_exists($Filename) || !is_readable($Filename)
		throw new Exception("{$Filename} not found or unreadable.");

		return file_get_contents($Filename);
	}

	protected function
	GetFileContents_ParseData(string $Data):
	StdClass {
	/*//
	check that the file was parsable.
	//*/

		$Obj = json_decode($Data);

		if(!is_object($Data))
		throw new Exception("Unable to parse data.");

		return $Obj;
	}

}



$DB = new Nether\Database;
$Query = NULL;

($Query = $DB->NewVerse())
->Select('Table')
->Fields(['One','Two','Three'])
->Where(['Five=:InputFive','Six=:InputSix'])
->Limit(25);

$Result = $DB->Query($Query,$Input);



class Project {

	public function
	DetermineThisValue():
	int {

		$Output = 0;
		$Child = NULL;

		foreach($this->TotallyAnArrayProperty as $Child) {
			if($Child->TotallyAnBoolProperty === TRUE)
			$Output++;
		}

		return $Output;
	}

}

 if($Stuff): 

public function AddTwo(Int $Input): Int;

public function AddTwo(int $Input): int;

use
\Nether as Nether,
\Local as Local;

use Nether;
use Local;