Why does a PHP function without parameters require parentheses?

I just spent 3 hours wondering why I couldn’t start the session, and then realized that I was using:

session_start;

when I should have used:

session_start();

I have not received any error messages!

Perhaps then I thought it was a lazy way to differentiate functions from variables, but then I remembered that this could not be the way variables require $

Can someone tell me why the brackets are needed, and also why the error does not occur when they are not used?

+3
source share
5 answers

I get a notification (setting error_reporting to E_ALL):

: undefined session_start - 'session_start' /t.php 5

, ( ), . , , , , , .

, , - , - , PHP , .

$myArray[myString] = 25;
+9

, ... , ... php.ini

+2

, PHP (, , , ).

PHP, , E_NOTICE, , , , , .

<?php
$foo = unknown_identifier;
echo 'Now printing: ' . $foo; // prints 'Now printing: unknown_identifier' (PHP 5.2.6)
?>

, , , E_NOTICE . , error_reporting:

<?php
error_reporting(E_ALL);

$foo = unknown_identifier;
echo 'Now printing: ' . $foo;
?>

"", Yacoby.

, E_ALL PHP 5.x. PHP 5 E_ALL | E_STRICT .

- : .

+1

, - , , (void) ( ). . , C, .

, echo functon PHP , - , - .

Take a look at http://en.wikipedia.org/wiki/Function (computer_science)

0
source

() means that the function must be called. Without this, you can pass the link. For example (PHP 5.3):

$callable = session_start;
$callable();
-1
source

Source: https://habr.com/ru/post/1745434/


All Articles