php Fatal error: Method name must be a string [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
why i get this error? how fix it? when run on server get Fatal error: Method name must be a string line 8
class Model extends Core_Model_Config_Data
{
protected function Load()
{
$a = file_properties();
$x0 = $this->$a["x0"](); line 8 error
$x0 = $this->$a["x1"]($x0);
$this->$a["x2"]($x0);
}
}
please help me.

Try this:
protected function Load()
{
$a = file_properties();
$f = $a['x0'];
$x0 = $this->$f();
$f = $a['x1'];
$x0 = $this->$f($x0);
$f = $a['x2'];
$this->$f($x0);
}
Obviously the values $a['x0'], $a['x1'], $a['x2'] must be strings and hold a valid method name for the class.

Right, there's a variety of possible reasons for your code throwing up errors:
What is $a["x0"]? is it a string? If so, does the method even exist?
Ambiguity: The preprocessor might have a hard time working out what you're trying to do, should the string value of $a be used to reference a property, that might be an array, that has a key "x0", which in turn might be a Closure instance, or a string that is a method name? use cruly braces to be clear: $this->{$a["x0"]}();
At no point are you cheking if the method exists, let alone if it can be called... where are your method_exists($this, $a["x0"]) and is_callable(array($this, $a["x0"])) checks?
Your code is flawed from the off, it's so incredibly error-prone... I wouldn't even bother working this one out. I'd set about rethinking my approach to whatever problem you're trying to solve here, and start over.

Related

mkdir() returns No such file or directory in <b>...</b> on line <b>..</b><br /> [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm PHP developer but i cant understand this error
$uid = $this->db->Tables("telegrambots")->search([
"telegrambotid" => $this->botKey
])['uniqueId'];
if (!file_exists("TelegramBotCommands/{$uid}"))
mkdir("TelegramBotCommands/{$uid}");
Eval is evil, you probably don't need it so don't use it. You want to make a call to a class with a dynamic name? Use this:
$dynamic_class_name = 'Video';
$video = new $dynamic_class_name();
That being said, your snippet with eval seems to work perfectly fine:
http://sandbox.onlinephpfunctions.com/code/e3bb43b1ccfd27365247120e9c5751aac9e2b4ce
You would have to check your logs as to what the error is.
EDIT:
As you said you are using namespaces, try to use the full classname including the namespace in the eval function (like new \namespace\Videos(.... Even better though: don't use eval!

Fatal error: Function name must be a string whilst it shouldn't [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have stumbled over the following error in PHP:
"Fatal error: Function name must be a string in
F:\Applications\xampp\htdocs\BTB_Sandbox\uploads.php on line 15"
and I don't know what the real problem is. Here is line 15 that the error is pointing at:
$error = $_FILES(['file_upload']['error']);
I hope you could help me, because I am kind of stuck now.
You are using $_FILES as a function because of ().
That way, PHP tries to call a function named as var $_FILES value, but this value it not a string (that's the error reported), it is an array.
Obviously, in your code line you are failing to use $_FILES, the right way is:
$error = $_FILES['file_upload']['error'];

"Call to a member function .. on a non-object" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Hi, I am following this guide and copying exactly what is posted (except the author forgot some curly brackets, and I changed passwords etc). My problem is in the register.inc.php file.
Here is the following error I receive when a user tries to register
Call to a member function prepare() on a non-object in /home/ / /includes/register.inc.php on line 48
Line 48 of the file is
$stmt = $members_mysqli->prepare($prep_stmt);
Here is the entire register.inc.php file:
http://pastebin.com/YcQ7unb0 (It's not being properly formatted on this site)
$members_mysqli is probably a typo. It was never created. You use another variable named $mysqli. Maybe that's the one you meant to use. Check your include files and make sure you actually instantiated $members_mysqli.
The "call to member function on non-object" error is thrown when you try to use an uncreated/uninstantiated variable as an object.
For example:
// create an object
$blah = new Blah();
// call a function on it
$blah->doSomething();
// no error, because $blah exists. however, if my next line is:
$blue->doSomething();
// I'd get an error because $blue was never created

Is PHP function names case-sensitive or not? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am from Java background.
In Java, every method has case-sensitive while calling. But in PHP, I didn't see the case-sensitive function name while calling the functions.
class Sample {
...
...
function sampleFunction() {
....
....
}
}
$obj = new Sample();
$obj->sampleFunction(); /* Proper call with function name */
$obj->samplefunction(); /* It should show undefined function error but it also calls sampleFunction() */
Can anyone clear my doubt why this is also called even non-case sensitive function name. And please give me how to restrict in PHP?
Thanks in advance.
They are case insensitive, see this:
Note: Function names are case-insensitive, though it is usually good
form to call functions as they appear in their declaration.
http://www.php.net/manual/en/functions.user-defined.php
Functions are not case sensitive, Variables are case sensitive.
you can read more info from manual :
http://fr.php.net/manual/en/functions.user-defined.php

"Indirect" isset() [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
function myCheck($in)
{ return isset($in); }
$var1='Something';
$var2='$var1';
$var3='$varNonExitant';
What I'm trying to achive is to use myCheck to evaluate the existance of the content like this:
myCheck($var2) return true;
myCheck($var3) return false;
isset() is not really a function: it's a language construct. As such, it's allowed to do some magic that's not available to regular functions, such as being fed with non-existing variables.
To sum up: you cannot replicate it with a custom function.
Edit:
As DaveRandom pointed out in a comment below, all you can do is come close by checking if a variable isset for example:
function variable_isset(&$variable = NULL) {
return isset($variable);
}
This approach offers two drawbacks though:
This works by passing the unset variable by reference, thus creating it when called. As it's NULL it is still not set.
It'll trigger an Undefined variable notice if the variable does not exist, ruining the whole concept of gracefully handling optional variables.
Most likely this should not be needed. So question remains why you can not use isset in the first place which would be much more needed to give you better guidance.
When you cyall myCheck($abc), with set $abc = 123, it gets myCheck(123). It isn't any valid argument for isset.
You have to give the function a string with variable name:
function isset_global($variable_name)
{
return isset($GLOBALS[$variable_name]);
}
Of course, I am also wondering, why to do this, but it answers the question as long as you check a global variable.

Categories