Posts Tagged: php

Edit Eclipse Generate Getter and Setters Format

For me, I like to always return $this when creating a setter class method when coding PHP. For example, to set an object to be freaky, I would create method like this. /** * Set to freaky or not freaky. * * @param boolean $freaky * @return $this */ public function setFreaky($freaky) { $freaky ===… Read more »

PHP Portable Paths

Frankly, I don’t care about people wanting to run my code on a Windows box and it not working. But in reality, for some reason, there are people who write code using computers running the Microsoft Windows operating system. Why don’t they use a Mac, or if they don’t have or want to spend the… Read more »

PHP Monolog Choking on Large Log Entries

I’m using Monolog to log XML coming into a SOAP service and some of the XML is really long. I’m using a LineLogParser and it’s calling preg_match to parse each line of the log. Well on the big XML files, preg_match was hitting a “backtrack” limit. What I had to do was crank up the… Read more »

PHP Get the First of Next Month

While having fun with dates, I needed to get the timestamp for the first of the next month, here’s how I did it with PHP. strtotime(date(‘m’, strtotime(‘+1 month’)) . ‘/01/’ . date(‘Y’, strtotime(‘+1 month’))); I then used that to create a PHP DateTime object like this. $date = new DateTime(); $date->setTimestamp(strtotime(date(‘m’, strtotime(‘+1 month’)) . ‘/01/’… Read more »

Symfony ChoiceType Default to Checkbox Checked

I’m rendering a bunch of checkboxes using a Symfony form type of ChoiceType and I want some of them to be checked by default. It’s basically a list of transactions and the ones that fail will be checked so that the user can fix whatever caused the problem and run them failed ones again. It… Read more »

Updating Ubuntu 14.04 Reverts Command-Line PHP to Version 7

PHP version 7 looks really cool and I can’t wait to start using it, but for now, I’m still on PHP 5.6. But every time I do an update on my Ubuntu dev box, it sets the PHP command-line to PHP version 7. Here’s how to switch it back on Ubunut 14.04. ln -sfn /usr/bin/php5.6… Read more »

Symfony Load Twig Template From String

As is always the case with PHP, or open source technology, there’s a gazillion ways to rule the world, or solve a problem. I had a problem with a Symfony app I was building. I needed to load the Twig template from a string variable rather than a file. To do so is easy. All… Read more »

PHP SoapClient Create An Array of Objects

In PHP, you can’t create an array with the same key more than once. You can’t do this. $array[‘transaction’] = “success”; $array[‘transaction’] = “fail”; Obviously, you can DO that, but “fail” will overwrite “success.” But when making Soap calls, it’s often necessary to pass in a structure like this. <users> <user> <firstname>Jamal</firstname> </user> <user> <firstname>Acacia</firstname>… Read more »