If you use PHP's list function to quickly extract array values out into dollar variables then you might have an issue where it just doesn't work for some reason. The problem is that list only works with numeric arrays. If you are using an associative array (with strings for keys instead of numbers) then list [...]
Archive: php
Static analysis is the process of parsing and searching through code without actually running it. It is the equivalent of someone opening your code base in their IDE and reading through it in detail. RIPS is a tool I have just come across for doing PHP static analysis. You just need a working Apache stack [...]
We are really pleased to announce the successful Zend Certification exam for two of our developers Bolaji and Martyn. It's really quite a hard exam to pass and definitely tests your knowledge of PHP to the limits. They found it challenging but nailed it. That means that we now have a 100% Zend Certified PHP [...]
If you need to clean up a URL and remove any double (or more) slashes that might have crept in, but need to keep the :// bit intact you might like this little function PLAIN TEXT PHP: protected function removeDoubleSlash($in) { return preg_replace('%([^:])([/]{2,})%', '\\1/', $in); } Handy More Reading:Magento [...]
If you are having issues running unit tests that work with sessions and call session_start(), you might see error messages like this: output started at "PHPUnit/Util/Printer.php:173" If you do, the solution is fairly simple. Just add the flag --stderr to PHPUnit eg PLAIN TEXT CODE: phpunit --stderr mytest.php If you are using Netbeans, you simply [...]
If you ever need to create a custom field to save data against a customer in Magento you will probably need to create a custom attribute. Creating the attribute is easy, in your modules install script you do: PLAIN TEXT PHP: <?php $installer = $this; $installer->startSetup(); $installer->addAttribute('customer', 'my_custom_attribute', array('type'=>'text')); $installer->endSetup(); Then on the customer object [...]
One of the features that makes PHP such a powerful language is it's arrays. They allow for really complex data structures to be stored and worked on really easy. One interesting aspect of them is that they maintain there index if emptied one element at a time. Taken from php.net: http://php.net/manual/en/language.types.array.php PLAIN TEXT PHP: <?php [...]
What can be true and false at the same time? PLAIN TEXT PHP: $a = "a"; $b = 0; if($a == true && $b == false && $a == $b) { echo "Passed"; } This is because PHP tries to convert "a" to a numeric, as there is no numeric value it [...]
Reading the generally very clear and concise Yii documentation you can quickly get started with the framework. However one issue that I struggled to be clear on is setting up the database driven authorisation system. I recommend reading this blog post which finally helped me to understand wth I was supposed to do. The official [...]
If you want to serve up text files for download (perhaps product feeds etc) then you might like this little snippet. Not only will it force the file to be downloaded but it allows you to specify a custom filename that it should be saved as. PLAIN TEXT PHP: if(isset($_GET['download_file'])){ header("Content-type: application/octet-stream"); [...]