Tuesday, January 11, 2011

Things I learned today about Yii and PHP

You can embed a value in a string by using double quotes, BUT it doesn't work for child objects. Example: "hi, my name is $user->name" outputs "hi, my name is neil", but "hi, my name is $account->user->name" does not work. BUT, if you wrap it in curly braces, it works, like this: "hi, my name is {$account->user->name}"

If you are using a client certificate with cUrl, then the certificate path is absolute. Example: curl_setopt($handle, CURLOPT_SSLCERT, 'absolute path to cert here');

In SimpleXML, if you use the simplexml_load_string function, and the xml tags have hyphens, then you have to use curly braces to access them. Example: $xml = simplexml_load_string($some_xml); $value = $xml->{'some-xml-tag-with-hyphens'};

Use strttotime to parse strings as dates.

I think I found a bug in Yii. Database column was DECIMAL(2,1), which should allow for example "3.1" as a value, but Yii restricts the length of input to two characters, and it should be three, due to the decimal. Can anyone confirm?

I hate SOAP, and I hate XML. Much love for REST and JSON.

cUrl is slightly faster than file_get_contents for http requests.

Yii is nice, but Zend sure has a lot of useful functions. I'll stick with Yii as my framework, but make liberal use of Zend Framework library. Same for ezComponents.

The blueprint css framework is pretty nice. Yii doesn't use all of it, so I would recommend investigating it.

You can't use an array reference with a function call, like you can in JavaScript. Example: echo functionThatReturnsAnArray()[0]; does not work.

    1 comment: