Re: [php-49] Type hinting exp4ect class if string is used?

From: Tim P.
Sent on: Tuesday, February 12, 2013 8:11 PM
Easy fix, just use magic comments

/* ohai newfag, make sure that $section is a string or all your base are belong to us */
public function setIniSection(string $section)







On Tue, Feb 12, 2013 at 10:18 AM, Jd Daniel <[address removed]> wrote:
Sounds familiar guys?

if I try public function setIniSection(string $section)
it expects a Class named string =( Any info? Code below even though it doesn't matter...


    /**
     * Cannibalize an Ini file and create definitions of a sub-selected content
     * @param   string $section   subsection of ini file
     * @return  definitions
     */
    public function setIniSection($section)
    {

        // fast primitive, because type hinting thinks string $section
        // means instanceof Class string =P Really PHP, really?
        if (!is_string($section)) trigger_error('Argument passed myst be of type string ' . gettype($section) . ' passed.');

        if (! file_exists(self::CONFIG_INI) {
            self::_throwException("Configuration Ini does not exist: " __DIR__ .'/' . self::CONFIG_INI);
        }

        $iniArray = parse_ini_file((__DIR__ . '/' . self::CONFIG_INI), true);
        foreach ($iniArray[$section] as $definitor => $value) {
            if (!defined($definitor)) define($definitor, $value);
        }

        return true;
    }

--
Jd Daniel || ERADO
Senior Applications Architect
7901 Delridge Way SW #36D, Seattle

C.    [masked]





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Jd Daniel ([address removed]) from The Seattle PHP Meetup Group.
To learn more about Jd Daniel, visit his/her member profile
Set my mailing list to email me As they are sent | In one daily email | Don't send me mailing list messages

Meetup, POB 4668 #37895 NY NY USA 10163 | [address removed]

Our Sponsors

  • TUNE

    Meeting space and food

  • PluralSight

    PluralSight subscriptions for developer training

  • Siteground

    Information coming Soon

  • O'Reilly

    Disc Code: PCBW is good for 40% off print and 50% off ebooks and videos

  • JetBrains PhpStorm

    Occasional free licenses to raffle off at meetups

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy