addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [php-49] Does this look ok for my constructor, or is it too hard to read?

From: Mike B.
Sent on: Thursday, February 14, 2013 7:59 AM
strpos() returns an int, not a bool. Seems a bit inconsistent to test NULL explicitly but not test the return from strpos() for != 0 explicitly.

Comments like "// !!!" could be more helpful.

On Wed, Feb 13, 2013 at 10:46 AM, Jd Daniel <[address removed]> wrote:
I know I overcomplicate stuff sometimes, just wanna make sure i'm not off the deep end for other devs. Cheers.

     * Creates a new Private_Service_Foo_Response object.
     * @param string $data Response data returned by Foo
     * @param array  $info HTTP {@link metadata}
     * @throws Private_Service_Foo_Exception
    public function __construct($data, array $info)
        $this->_dataString = $data;
        $this->_httpInfo   = $info;

        // If no error occurred, attempt to convert returned data to an object
        if(!$this->isError() && isset($info['url']))
            // Convert JSON to StdClass object, XML to SimpleXMLElement
            if(strpos($info['url'], '.json'))
                // throw error on bad json
                if (NULL !== ($this->dataObject = json_decode($data)) && JSON_ERROR_NONE === json_last_error())
                    self::_throwException('Error parsing JSON file ' . $file . ': ' . json_last_error());
            else if(strpos($info['url'], '.xml'))
                // throw error on bad xml
                libxml_use_internal_errors(true); // !!!
                if (FALSE === ($this->dataObject = simplexml_load_string($data)))
                    self::_throwException('Error parsing XML file ' . $file . ': ' . implode(', ', libxml_get_errors()));

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

  • PluralSight

    PluralSight subscriptions for developer training

  • 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

  • DynaTrace

    Find yourself, promote yourself, stay true to yourself.

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