Cara menggunakan php echo shorthand

echo "echo does not require parentheses.";

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', "\n";
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";

// No newline or space is added; the below outputs "helloworld" all on one line
echo "hello";
echo "world";

// Same as above
echo "hello", "world";

echo "This string spans
multiple lines. The newlines will be
output as well";

echo "This string spans\nmultiple lines. The newlines will be\noutput as well.";

// The argument can be any expression which produces a string
$foo = "example";
echo "foo is $foo"; // foo is example

$fruits = ["lemon", "orange", "banana"];
echo implode(" and ", $fruits); // lemon and orange and banana

// Non-string expressions are coerced to string, even if declare(strict_types=1) is used
echo 6 * 7; // 42

// Because echo does not behave as an expression, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', "\n";
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
0

// Strings can either be passed individually as multiple arguments or
// concatenated together and passed as a single argument
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', "\n";
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "\n";
1

Scalar type declarations come in two flavours: coercive (default) and strict. The following types for parameters can now be enforced (either coercively or strictly): strings (string), integers (int), floating-point numbers (float), and booleans (bool). They augment the other types introduced in PHP 5: class names, interfaces, array and callable.

// Coercive mode
function sumOfInts(int ...$ints)
{
return array_sum($ints);
}

var_dump(sumOfInts(2, '3', 4.1));

The above example will output:

To enable strict mode, a single declare directive must be placed at the top of the file. This means that the strictness of typing for scalars is configured on a per-file basis. This directive not only affects the type declarations of parameters, but also a function's return type (see return type declarations, built-in PHP functions, and functions from loaded extensions.

Full documentation and examples of scalar type declarations can be found in the type declaration reference.

Return type declarations

PHP 7 adds support for return type declarations. Similarly to argument type declarations, return type declarations specify the type of the value that will be returned from a function. The same types are available for return type declarations as are available for argument type declarations.

object(class@anonymous)#2 (0) {
}
0

object(class@anonymous)#2 (0) {
}
1

The above example will output:

Array
(
    [0] => 6
    [1] => 15
    [2] => 24
)

Full documentation and examples of return type declarations can be found in the return type declarations. reference.

Null coalescing operator

The null coalescing operator (

object(class@anonymous)#2 (0) {
}
2) has been added as syntactic sugar for the common case of needing to use a ternary in conjunction with isset(). It returns its first operand if it exists and is not
object(class@anonymous)#2 (0) {
}
3; otherwise it returns its second operand.

object(class@anonymous)#2 (0) {
}
4

object(class@anonymous)#2 (0) {
}
5

Spaceship operator

The spaceship operator is used for comparing two expressions. It returns -1, 0 or 1 when $a is respectively less than, equal to, or greater than $b. Comparisons are performed according to PHP's usual type comparison rules.

object(class@anonymous)#2 (0) {
}
6

object(class@anonymous)#2 (0) {
}
7

object(class@anonymous)#2 (0) {
}
8

Constant arrays using define()

Array constants can now be defined with define(). In PHP 5.6, they could only be defined with

object(class@anonymous)#2 (0) {
}
9.

ª
ª (same as before but with optional leading 0's)
香
0

ª
ª (same as before but with optional leading 0's)
香
1

Anonymous classes

Support for anonymous classes has been added via

ª
ª (same as before but with optional leading 0's)
香
2. These can be used in place of full class definitions for throwaway objects:

ª
ª (same as before but with optional leading 0's)
香
3

ª
ª (same as before but with optional leading 0's)
香
4

ª
ª (same as before but with optional leading 0's)
香
5

ª
ª (same as before but with optional leading 0's)
香
6

ª
ª (same as before but with optional leading 0's)
香
7

ª
ª (same as before but with optional leading 0's)
香
8

The above example will output:

object(class@anonymous)#2 (0) {
}

Full documentation can be found in the anonymous class reference.

Unicode codepoint escape syntax

This takes a Unicode codepoint in hexadecimal form, and outputs that codepoint in UTF-8 to a double-quoted string or a heredoc. Any valid codepoint is accepted, with leading 0's being optional.

ª
ª (same as before but with optional leading 0's)
香
9

The above example will output:

ª
ª (same as before but with optional leading 0's)
香

Closure::call() is a more performant, shorthand way of temporarily binding an object scope to a closure and invoking it.

10ffff
COMMERCIAL AT
bool(true)
0

10ffff
COMMERCIAL AT
bool(true)
1

10ffff
COMMERCIAL AT
bool(true)
2

The above example will output:

This feature seeks to provide better security when unserializing objects on untrusted data. It prevents possible code injections by enabling the developer to whitelist classes that can be unserialized.

10ffff
COMMERCIAL AT
bool(true)
3

10ffff
COMMERCIAL AT
bool(true)
4

10ffff
COMMERCIAL AT
bool(true)
5

The new IntlChar class seeks to expose additional ICU functionality. The class itself defines a number of static methods and constants that can be used to manipulate unicode characters.

10ffff
COMMERCIAL AT
bool(true)
6

The above example will output:

10ffff
COMMERCIAL AT
bool(true)

In order to use this class, the Intl extension must be installed.

Expectations

are a backwards compatible enhancement to the older assert() function. They allow for zero-cost assertions in production code, and provide the ability to throw custom exceptions when the assertion fails.

While the old API continues to be maintained for compatibility, assert() is now a language construct, allowing the first parameter to be an expression rather than just a string to be evaluated or a bool value to be tested.

10ffff
COMMERCIAL AT
bool(true)
7

10ffff
COMMERCIAL AT
bool(true)
8

10ffff
COMMERCIAL AT
bool(true)
9

The above example will output:

Fatal error: Uncaught CustomError: Some error message

Full details on this feature, including how to configure it in both development and production environments, can be found in the of the assert() reference.

Group Fatal error: Uncaught CustomError: Some error message 0 declarations

Classes, functions and constants being imported from the same

Fatal error: Uncaught CustomError: Some error message
1 can now be grouped together in a single
Fatal error: Uncaught CustomError: Some error message
0 statement.

Fatal error: Uncaught CustomError: Some error message
3

Fatal error: Uncaught CustomError: Some error message
4

Fatal error: Uncaught CustomError: Some error message
5

Fatal error: Uncaught CustomError: Some error message
6

Generator Return Expressions

This feature builds upon the generator functionality introduced into PHP 5.5. It enables for a

Fatal error: Uncaught CustomError: Some error message
7 statement to be used within a generator to enable for a final expression to be returned (return by reference is not allowed). This value can be fetched using the new
Fatal error: Uncaught CustomError: Some error message
8 method, which may only be used once the generator has finished yielding values.

Fatal error: Uncaught CustomError: Some error message
9

int0

int1

int2

The above example will output:

Being able to explicitly return a final value from a generator is a handy ability to have. This is because it enables for a final value to be returned by a generator (from perhaps some form of coroutine computation) that can be specifically handled by the client code executing the generator. This is far simpler than forcing the client code to firstly check whether the final value has been yielded, and then if so, to handle that value specifically.

Generator delegation

Generators can now delegate to another generator, Traversable object or array automatically, without needing to write boilerplate in the outermost generator by using the construct.

int4

int5

int6

The above example will output:

Integer division with intdiv()

The new intdiv() function performs an integer division of its operands and returns it.

int7

The above example will output:

Session options

session_start() now accepts an array of options that override the session configuration directives normally set in php.ini.

These options have also been expanded to support , which is on by default and causes PHP to only overwrite any session file if the session data has changed, and int8, which is an option that can only be passed to session_start() to indicate that the session data should be read and then the session should immediately be closed unchanged.

For example, to set to int9 and immediately close the session after reading it:

bool0

The new preg_replace_callback_array() function enables code to be written more cleanly when using the preg_replace_callback() function. Prior to PHP 7, callbacks that needed to be executed per regular expression required the callback function to be polluted with lots of branching.

Now, callbacks can be registered to each regular expression using an associative array, where the key is a regular expression and the value is a callback.

CSPRNG Functions

Two new functions have been added to generate cryptographically secure integers and strings in a cross platform way: random_bytes() and random_int().

list() can always unpack objects implementing ArrayAccess

Previously, list() was not guaranteed to operate correctly with objects implementing ArrayAccess. This has been fixed.