Skip to main content

23 posts tagged with "PHP"

PHP Programming Language and Runtime

View All Tags

How to Write to Standard Error in PHP

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

A command-line PHP script has two output channels: echo writes to standard output, where results go, and STDERR is standard error, for problems. Write a warning with fwrite(STDERR, ...) and it still reaches the screen when the results go into a file.

How to Read an Environment Variable in PHP

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Settings that change between computers, such as a database address or an API key, belong in environment variables. PHP reads one with getenv('NAME'), which returns the value as a string, or false when the variable isn't set.

How to Define a Function in PHP

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

A function gives a name to a piece of work so you can run it with different values whenever you need it. In PHP you write one with the function keyword, list its parameters in brackets and hand back the result with return.

How to Import a Class in PHP with use

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

PHP classes usually live in namespaces, such as App\Greeter or Firebase\JWT\JWT. A use statement at the top of a file imports one by its full name, so the rest of the file can call it by its short name.