call_user_func_array throws an error when the method exist
This is how I am reaching the _call
method:
$model->delivery_price = $currencyConverter->convertPriceByGivenCurrencies(
$model->delivery_price,
$currency->id,
$model->order_currency
);
The function throws an error but the method exists below it. My __call
looks like:
public function __call($name, $params)
{
if(method_exists(CurrencyConverter::className(), $name)){
if($params[0] == 0 || $params[0]){
call_user_func_array($name, $params);
}else{
throw new Exception('Price must be a valid number!');
}
}
throw new NotFoundException('Function doesn't exist');
}
It passes the if
condition but after that the error occures:
call_user_func_array() expects parameter 1 to be a valid callback, function 'convertPriceByGivenCurrencies' not found or invalid function name
And this is the convertPriceByGivenCurrencies
method which is landed in the below the _call
:
protected function convertPriceByGivenCurrencies($product_price, $product_price_currency_id, $select_currency_id)
{
............
}
What am I doing wrong here ? Thank you!
php
add a comment |
This is how I am reaching the _call
method:
$model->delivery_price = $currencyConverter->convertPriceByGivenCurrencies(
$model->delivery_price,
$currency->id,
$model->order_currency
);
The function throws an error but the method exists below it. My __call
looks like:
public function __call($name, $params)
{
if(method_exists(CurrencyConverter::className(), $name)){
if($params[0] == 0 || $params[0]){
call_user_func_array($name, $params);
}else{
throw new Exception('Price must be a valid number!');
}
}
throw new NotFoundException('Function doesn't exist');
}
It passes the if
condition but after that the error occures:
call_user_func_array() expects parameter 1 to be a valid callback, function 'convertPriceByGivenCurrencies' not found or invalid function name
And this is the convertPriceByGivenCurrencies
method which is landed in the below the _call
:
protected function convertPriceByGivenCurrencies($product_price, $product_price_currency_id, $select_currency_id)
{
............
}
What am I doing wrong here ? Thank you!
php
When you are checking whether the method name exists, you are passing a class name to do so. But where in yourcall_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.
– misorude
Nov 13 '18 at 7:44
add a comment |
This is how I am reaching the _call
method:
$model->delivery_price = $currencyConverter->convertPriceByGivenCurrencies(
$model->delivery_price,
$currency->id,
$model->order_currency
);
The function throws an error but the method exists below it. My __call
looks like:
public function __call($name, $params)
{
if(method_exists(CurrencyConverter::className(), $name)){
if($params[0] == 0 || $params[0]){
call_user_func_array($name, $params);
}else{
throw new Exception('Price must be a valid number!');
}
}
throw new NotFoundException('Function doesn't exist');
}
It passes the if
condition but after that the error occures:
call_user_func_array() expects parameter 1 to be a valid callback, function 'convertPriceByGivenCurrencies' not found or invalid function name
And this is the convertPriceByGivenCurrencies
method which is landed in the below the _call
:
protected function convertPriceByGivenCurrencies($product_price, $product_price_currency_id, $select_currency_id)
{
............
}
What am I doing wrong here ? Thank you!
php
This is how I am reaching the _call
method:
$model->delivery_price = $currencyConverter->convertPriceByGivenCurrencies(
$model->delivery_price,
$currency->id,
$model->order_currency
);
The function throws an error but the method exists below it. My __call
looks like:
public function __call($name, $params)
{
if(method_exists(CurrencyConverter::className(), $name)){
if($params[0] == 0 || $params[0]){
call_user_func_array($name, $params);
}else{
throw new Exception('Price must be a valid number!');
}
}
throw new NotFoundException('Function doesn't exist');
}
It passes the if
condition but after that the error occures:
call_user_func_array() expects parameter 1 to be a valid callback, function 'convertPriceByGivenCurrencies' not found or invalid function name
And this is the convertPriceByGivenCurrencies
method which is landed in the below the _call
:
protected function convertPriceByGivenCurrencies($product_price, $product_price_currency_id, $select_currency_id)
{
............
}
What am I doing wrong here ? Thank you!
php
php
asked Nov 13 '18 at 7:38
Toma TomovToma Tomov
612216
612216
When you are checking whether the method name exists, you are passing a class name to do so. But where in yourcall_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.
– misorude
Nov 13 '18 at 7:44
add a comment |
When you are checking whether the method name exists, you are passing a class name to do so. But where in yourcall_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.
– misorude
Nov 13 '18 at 7:44
When you are checking whether the method name exists, you are passing a class name to do so. But where in your
call_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.– misorude
Nov 13 '18 at 7:44
When you are checking whether the method name exists, you are passing a class name to do so. But where in your
call_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.– misorude
Nov 13 '18 at 7:44
add a comment |
2 Answers
2
active
oldest
votes
$name
by itself is not a known function; it seems to be a method in the CurrencyConverter
class.
So to call it, assuming it is a static method, you would need something like:
CurrencyConverter::$name(...$params);
Note that you need the ...
operator to unpack $params
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am onPHP Version 7.2.6-1
. it is not usable on higher version ?
– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
add a comment |
Calling it with
call_user_func_array($name, $params);
it is expecting a standalone function called $name
.
As it's a method in a class you need to add this information to the callable, if you want to call it on the current instance then use
call_user_func_array(array($this,$name), $params);
If it isn't a method in the current instance, then replace $this
with the appropriate instance. Or change the method to be static
and replace $this
with the class name.
__call
andprotected function convertPriceByGivenCurrencies
are both inCurrencyConverter
class. And the variable$currencyConverter
is instance of theCurrencyConverter
class. Sorry about the unclear explanation :)
– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276038%2fcall-user-func-array-throws-an-error-when-the-method-exist%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$name
by itself is not a known function; it seems to be a method in the CurrencyConverter
class.
So to call it, assuming it is a static method, you would need something like:
CurrencyConverter::$name(...$params);
Note that you need the ...
operator to unpack $params
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am onPHP Version 7.2.6-1
. it is not usable on higher version ?
– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
add a comment |
$name
by itself is not a known function; it seems to be a method in the CurrencyConverter
class.
So to call it, assuming it is a static method, you would need something like:
CurrencyConverter::$name(...$params);
Note that you need the ...
operator to unpack $params
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am onPHP Version 7.2.6-1
. it is not usable on higher version ?
– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
add a comment |
$name
by itself is not a known function; it seems to be a method in the CurrencyConverter
class.
So to call it, assuming it is a static method, you would need something like:
CurrencyConverter::$name(...$params);
Note that you need the ...
operator to unpack $params
$name
by itself is not a known function; it seems to be a method in the CurrencyConverter
class.
So to call it, assuming it is a static method, you would need something like:
CurrencyConverter::$name(...$params);
Note that you need the ...
operator to unpack $params
edited Nov 13 '18 at 7:49
answered Nov 13 '18 at 7:44
jeroenjeroen
81.8k1698122
81.8k1698122
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am onPHP Version 7.2.6-1
. it is not usable on higher version ?
– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
add a comment |
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am onPHP Version 7.2.6-1
. it is not usable on higher version ?
– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
But the unpacking is avaible in 5.6 only. At least this is what the PHPStorm says :)
– Toma Tomov
Nov 13 '18 at 8:04
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
@TomaTomov That's right, if you are on an earlier version you should probably upgrade :-)
– jeroen
Nov 13 '18 at 8:09
In fact I am on
PHP Version 7.2.6-1
. it is not usable on higher version ?– Toma Tomov
Nov 13 '18 at 8:12
In fact I am on
PHP Version 7.2.6-1
. it is not usable on higher version ?– Toma Tomov
Nov 13 '18 at 8:12
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
@TomaTomov It is available from 5.6 on, so you can use it without any problems. Does PHPStorm know you are on 7.2?
– jeroen
Nov 13 '18 at 8:28
1
1
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
Guess he doesn't know because it is working :) Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:41
add a comment |
Calling it with
call_user_func_array($name, $params);
it is expecting a standalone function called $name
.
As it's a method in a class you need to add this information to the callable, if you want to call it on the current instance then use
call_user_func_array(array($this,$name), $params);
If it isn't a method in the current instance, then replace $this
with the appropriate instance. Or change the method to be static
and replace $this
with the class name.
__call
andprotected function convertPriceByGivenCurrencies
are both inCurrencyConverter
class. And the variable$currencyConverter
is instance of theCurrencyConverter
class. Sorry about the unclear explanation :)
– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
add a comment |
Calling it with
call_user_func_array($name, $params);
it is expecting a standalone function called $name
.
As it's a method in a class you need to add this information to the callable, if you want to call it on the current instance then use
call_user_func_array(array($this,$name), $params);
If it isn't a method in the current instance, then replace $this
with the appropriate instance. Or change the method to be static
and replace $this
with the class name.
__call
andprotected function convertPriceByGivenCurrencies
are both inCurrencyConverter
class. And the variable$currencyConverter
is instance of theCurrencyConverter
class. Sorry about the unclear explanation :)
– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
add a comment |
Calling it with
call_user_func_array($name, $params);
it is expecting a standalone function called $name
.
As it's a method in a class you need to add this information to the callable, if you want to call it on the current instance then use
call_user_func_array(array($this,$name), $params);
If it isn't a method in the current instance, then replace $this
with the appropriate instance. Or change the method to be static
and replace $this
with the class name.
Calling it with
call_user_func_array($name, $params);
it is expecting a standalone function called $name
.
As it's a method in a class you need to add this information to the callable, if you want to call it on the current instance then use
call_user_func_array(array($this,$name), $params);
If it isn't a method in the current instance, then replace $this
with the appropriate instance. Or change the method to be static
and replace $this
with the class name.
edited Nov 13 '18 at 7:51
answered Nov 13 '18 at 7:44
Nigel RenNigel Ren
25.5k61832
25.5k61832
__call
andprotected function convertPriceByGivenCurrencies
are both inCurrencyConverter
class. And the variable$currencyConverter
is instance of theCurrencyConverter
class. Sorry about the unclear explanation :)
– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
add a comment |
__call
andprotected function convertPriceByGivenCurrencies
are both inCurrencyConverter
class. And the variable$currencyConverter
is instance of theCurrencyConverter
class. Sorry about the unclear explanation :)
– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
__call
and protected function convertPriceByGivenCurrencies
are both in CurrencyConverter
class. And the variable $currencyConverter
is instance of the CurrencyConverter
class. Sorry about the unclear explanation :)– Toma Tomov
Nov 13 '18 at 8:03
__call
and protected function convertPriceByGivenCurrencies
are both in CurrencyConverter
class. And the variable $currencyConverter
is instance of the CurrencyConverter
class. Sorry about the unclear explanation :)– Toma Tomov
Nov 13 '18 at 8:03
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
Your answer also works and both gave me some new knowledges. I wish I could mark more than 1 best answers. Thank you very much!
– Toma Tomov
Nov 13 '18 at 8:51
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276038%2fcall-user-func-array-throws-an-error-when-the-method-exist%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When you are checking whether the method name exists, you are passing a class name to do so. But where in your
call_user_func_array
call are you referring to that same class …? You are passing the function name only there, so it looks for a standalone function of that name.– misorude
Nov 13 '18 at 7:44