0

I want to call the function xxx() and execute getCdl(). In getCdl() function i want to call the method dynamically. But this gives an error Call to undefined function trader_​cdl2crows. But when i execute trader_​cdl2crows() directly it works.

How can achieve this? :)

Functions:

public function xxx(){
$cdls = [
    'trader_​cdl2crows',
    'trader_​cdl3blackcrows',
    'trader_​cdl3inside',
    'trader_​cdl3linestrike',
    etc,etc,etc
$result = [];
foreach ($cdls as $cdl) {
    $result[$cdl] = $this->getCdl($cdl,$ticksPerType);
}
vardump($result);
}

private function getCdl($method,$ticksPerType){
return $method(
    $ticksPerType[$this->ticks::TICK_TYPE_OPEN],
    $ticksPerType[$this->ticks::TICK_TYPE_HIGH],
    $ticksPerType[$this->ticks::TICK_TYPE_LOW],
    $ticksPerType[$this->ticks::TICK_TYPE_CLOSE]
);
}
6
  • @Jeto just params, for all functions the same Commented Mar 26, 2019 at 3:53
  • Is trader_​cdl2crows a function, or is it a method of your class? (same for others) Commented Mar 26, 2019 at 3:54
  • existing function/method perl package Commented Mar 26, 2019 at 3:55
  • There are actually weird invisible characters in your function names, try copy pasting "trader_​cdl2crows" from your sample array here. This is probably your issue (I'll post this as an answer if you can confirm it). You can even put it in your URL bar / a SO comment or any text editor and see that you can hit the arrow keys twice after between _ and c. Commented Mar 26, 2019 at 3:59
  • Is this better? Commented Mar 26, 2019 at 4:03

1 Answer 1

2

Your function names, such as trader_​cdl2crows, have an zero-width space character right after the _ character.

Try encoding it using this tool for instance and it will give you: trader_​cdl2crows for the first function (​ is that zero-width char), and similar results for the rest of them. You can also notice by attempting to use arrow keys while editing these names within any input field/text editor such as a SO comment (need two "steps" to go from _ to c and vice-versa).

So replace your array with this:

$cdls = [
  'trader_cdl2crows',
  'trader_cdl3blackcrows',
  'trader_cdl3inside',
  'trader_cdl3linestrike',
  // if you have more function names, rewrite them here
];

This looks the exact same but does not have the invisible characters in it.

Sign up to request clarification or add additional context in comments.

3 Comments

Wow, Good find. How did you find that ? Select->SHIFT+RIGHT?
Actually I copy-pasted OP's code into IntelliJ's text editor and these characters appear as spaces there, I was wondering why the f*** IJ added those and then I figured it out :)
pffff, that was it... coppied the function names from here php.net/manual/en/function.trader-cdlengulfing.php and that coused the weird characters, thanks for your help! It works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.