How do I concatenate a variable into a class with Static function?

Asked

Viewed 61 times

1

Guys I’m having a problem, I have function that when passing card number returns the flag name (visa, Maxcard etc)

And I need to return the flag name within a Statica function

 $bandeira = getBandeiraByNumber("55523131232131"); retorna string visa
 $card->setCreditCardBrand(\Gateway\One\DataContract\Enum\CreditCardBrandEnum::$bandeira);

Here is the play

CreditCardBrandEnum::$bandeira

It returns this error

Fatal error: Access to undeclared static property: Gateway\One\DataContract\Enum\CreditCardBrandEnum::$bandeira in /var/www/html/exec/mundipagg/Mundipagg.php on line 148

Abstract class is like this.

namespace Gateway One Datacontract Enum;

abstract class CreditCardBrandEnum
{
    const VISA = 'Visa';
    const MASTERCARD = 'Mastercard';
    const HIPERCARD = 'Hipercard';
    const AMEX = 'Amex';
    const DINERS = 'Diners';
    const ELO = 'Elo';
    const AURA = 'Aura';
    const DISCOVER = 'Discover';
    const CASASHOW = 'CasaShow';
    const HAVAN = 'Havan';
    const HUGCARD = 'HugCard';
    const ANDARAKI = 'AndarAki';
    const LEADERCARD = 'LearderCard';
}

In case I want to turn a variable into const Static, but I’m not getting it.

  • What he tries to read is \Gateway\One\DataContract\Enum\CreditCardBrandEnum::visa Does this exist in the class? See the constant capitalization too, if possible add to the question.

  • @rray yes there is, I re-edited. da a look

1 answer

2


You need to pass the correct value to access the constant, in case visa is minuscule when it should be in upper case, use a function to leave the returno in upper case as strtoupper() or mb_convert_case() for characters with multibyte Encode.

$bandeira = strtoupper(getBandeiraByNumber("55523131232131"));
$card->setCreditCardBrand($bandeira);

or

$bandeira = mb_convert_case(getBandeiraByNumber("55523131232131"), MB_CASE_UPPER);
  • It worked I love you thanks!

  • @Tutijapawada really worked?

  • Yes it was case-sensitive.

  • I put a strupper in the flag function Return

  • @Tutijapawada did some tests here didn’t work xD which version of php is using?

  • @Tutijapawada you did something like this, $card->setCreditCardBrand(strtoupper($bandeira)); ?

  • almost that, but I put strupper in the return of function $flag getBandeiraByNumber

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.