This question already has answers here:
PHP Error: Function name must be a string
(8 answers)
Closed 6 years ago.
I added following few lines on top of my PHP code, but it is giving error
the error is
Function name must be a string in
/home/developeriq/public_html/doylesweb/hotel_search.php on line 3
if(!isset($_session)) {
$session_start();}
Your code is wrong:
if(!isset($_session)) {
$session_start();}
$session_start() should be session_start(). $ is for variables, session_start() is a function, not a variable, thus, $ is not required.
Also, it must be capitalised as it's a superglobal array. (Credits to #AkshayPrakash for pointing out)
if(!isset($_SESSION)) {
session_start();}
Documentation: http://php.net/manual/en/reserved.variables.session.php
Related
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
I have 2 php files inside joomla and I want to make a variable from php-file 1 available in php-file 2.
php-file_1.php
$a_variable = $input->getString('text');
php-file_2.php
include(php-file_1.php);
echo $a_variable;
I get Notice: Undefined variable: a_variable in /var/www/vhosts/a_domain.de/httpdocs/php-file_2.php on line 2
what's wrong here?
include and require are not functions, they are language constructs. Therefore they need to be used without brackets.
Either way, you missed quotes around php-file_1.php.
include 'php-file_1.php'; should work fine.
This question already has answers here:
Laravel 5 Function name must be a string bug
(2 answers)
PHP Error: Function name must be a string
(8 answers)
Closed 3 years ago.
error for intialize variable
$errors=array();
$errors =[];
If i intialize my variable errors to array() it gives the error, if with [] there is no error can someone explain why?
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?
(3 answers)
Closed 5 years ago.
In first.php i have $name = "Josh". How to echo $name in secound.php. Both are in same folder.
In first.php
$name = "Josh";
In secound.php
echo $name;
Notice: Undefined variable: name in D:\XAMPP\htdocs\Folder\secound.php on line 2
Edit
include 'first.php';
echo $name;
To access the data in the second file, you'll need to include it.
At the top of your secound.php script, add this code:
include 'first.php';
You could also use require, like this:
require 'first.php';
The difference between the two can be found in the PHP manual:
require is identical to include except upon failure it will also
produce a fatal E_COMPILE_ERROR level error. In other words, it will
halt the script whereas include only emits a warning (E_WARNING) which
allows the script to continue.
This question already has answers here:
Weird PHP error: 'Can't use function return value in write context'
(12 answers)
Closed 6 years ago.
I get the error in the subject. Also I spent ages on google and found dozens of resources having the same error, but still I can't figure out what the issue is.
This is my code:
<?php
if(empty(trim($_POST["user"])) || empty(trim($_POST["text"]))) {
echo "no luck";
}
?>
PHP Fatal error: Can't use function return value in write context in
/var/www/test.php on on line 2
If you refer to a manual, you will see
Determine whether a variable is considered to be empty.
The result of trim passed to empty is not a variable.
So your options are:
$user = trim($_POST['user']);
if (!empty($user)) { }
Or php5.5, in which
empty() now supports expressions
This question already has answers here:
What does it mean to start a PHP function with an ampersand?
(3 answers)
Closed 7 years ago.
I'm using a CMS package written in PHP. In one of it's core files I saw following line that is for defining a function in a class body.
public static function &getLib($sClass, $aParams = array()) {
// Code
}
I didn't understand why the function name 'getLib' has been prepended with the ampersand(&) sign? I've never seen such thing before.
Can someone please explain me in detail why such thing has been done and what's the benefit it has over simply using the function name?
It means the function should return a reference to a variable rather than just the value itself.