Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Tomas Votruba:
5 Gotchas of the Bin File in PHP CLI Applications
Aug 02, 2018 @ 17:47:03

Tomas Votruba has a new post to his site sharing five "gotchas" in CLI applications as it relates to the "bin" file.

This post from Master PHP CLI Apps with Symfony cluster will focus on bin files. It's the smallest part of PHP CLI Application, so I usually start with it.

Yet, there are still a few blind paths you can struggle with. I'll drop a few extra tricks to make your bin file clean and easy to maintain.

He starts with a brief definition of what a "bin" file is before getting into his list of "gotchas":

  • recommendations about naming and location of the file
  • setting it up to be autoloaded by Composer
  • including the right "shebang" to have it executed by the correct program
  • changing access rights
  • symlinking in Composer

The post ends with the complete code required to build a simple Symfony CLI application that will autoload libraries correctly and be executable by the system's php binary.

tagged: gotcha top5 list cli commandline application symfony tutorial

Link: https://www.tomasvotruba.cz/blog/2018/08/02/5-gotchas-of-the-bin-file-in-php-cli-applications/

Mark Baker:
PHP Generators – Sending “Gotchas”
Oct 11, 2016 @ 16:54:52

In this post to his site Mark Baker has shared some "sending gotchas" when generators are used in you PHP code. The focus of the article is on the "sending" part, pushing data into the generator for evaluation and use.

If you’re reading this, you’re probably already aware of just how useful PHP’s Generators are for improving performance and/or reducing memory overheads while keeping your code clean and easy to read.

Unlike their equivalent in some programming languages, PHP’s Generators allow you to send data into the Generator itself; not simply at initialisation (the arguments that we pass to the Generator when instantiating it); but also between iterations. This has its own uses, and again, allows us to move code from our main blocks and methods into the Generator itself. [...] However, there are a few “gotchas” when we combine Generators that both return and accept data in this way, and it really helps to be aware of them when we’re developing, otherwise it can create problems.

He starts simple, showing a generator that uses integers passed in as the starting number and addition interval for each loop. He gets a bit more complex in his next example, having a method called inside the loop. While the first instance of this behaves as expected, the second (after minor modification) yields unexpected results. He walks you through what's happening to produce those results and one possibility on how to get it corrected.

tagged: generator gotcha issue unexpected results debugging workaround

Link: https://markbakeruk.net/2016/10/08/php-generators-sending-gotchas/

Lars Tesmer's Blog:
Learning Ruby: Gotchas and Pitfalls for PHP Programmers
Sep 14, 2011 @ 14:48:42

Lars Tesmer is currently in the process of learning Ruby. He' been working through the tutorials and some sample scripts and has come across some pitfalls along the way. In his latest post he shares four of them that've stood out in his development so far.

I’m currently learning Ruby. In this post I'll list some pitfalls for programmers coming from PHP that would probably cause some confusion if you aren't aware of them. This list is by no means complete, while I learn Ruby I'll very probably encounter more gotchas, which I will blog about, too.

For each of his four examples, he gives the code PHP developers are used to seeing and the Ruby code that may or may not do what you'd expect:

  • Arrays are continuous
  • Zero is not falsy
  • The keywords private and protected
  • There's no static keyword
tagged: learn ruby pitfall gotcha programming language common

Link:

CodeFury.net:
CodeIgniter/PHP + IIS + MySQL + MSSQL: It Works!
Jan 13, 2011 @ 17:09:50

Kenny Katzgrau has a recent post on the Code Fury blog talking about the combination of CodeIgniter, IIS, MySQL and MSSQL and how it all works in his installation (after a few small gotchas).

There are a lot of people out there who call themselves "LAMP" developers — short for Linux, Apache, MySQL, PHP. That’s the standard configuration for production PHP applications. Recently, I ended up having to build a CodeIgniter application on Windows, IIS, Mysql+MS-SQL, and PHP. Sound like there are bound to be issues? You bet, and it especially hurts because now I'm a real-live WIMP developer. And what made it even more interesting was that due to constraints, I had to develop the application in Ubuntu and deploy to Windows for production.

He includes the list of the "gotchas" that he came across when doing the installation - six of them:

  • PHP and MSSQL on Ubuntu
  • PHP and MSSQL on Windows
  • mssql vs. sqlsrv
  • File Permissions and Logging
  • No .htaccess Fo' You!
  • 2 Databases, 1 Application
tagged: codeigniter iis mysql mssql gotcha install

Link:

Matthew Turland's Blog:
Gotcha on Scraping .NET Applications with PHP and cURL
Jul 01, 2010 @ 13:51:36

New on his blog today Matthew Turland has posted about a "gotcha" he came across when working with cURL to pull down information (scrape content) from a remote .NET application.

I recently wrote a PHP script to scrape data from a .NET application. In the process of developing this script, I noticed something interesting that I thought I’d share. In this case, I was using the cURL extension, but the tip isn’t necessarily specific to that. One thing my script did was submit a POST request to simulate a form submission. [...] The issue I ran into had to do with a behavior of the CURLOPT_POSTFIELDS setting that’s easy to overlook.

The problem was something cURL does automatically - change the header for the content type because you're sending an array. Thankfully, with the help of a call to http_build_query to encode it correctly, the request will use the right headers.

tagged: net application scrape content gotcha curl

Link:

Christian Wenz's Blog:
Serendipity Upgrade to v 1.5.x Gotcha
Dec 24, 2009 @ 12:44:55

Christian Wenz points out a "gotcha" for those upgrading Serendipity to the latest 1.5.x version - an issue with a SQL script not being run.

I just updated Serendipity to version 1.5.1 on one of our servers; yet afterwards I could not log in anymore. Also, Serendipity reported that version 1.5.1 was present, although I did not run the update script from the admin console yet. At first I thought I did something wrong, but a s9y forum posting described a similar issue.

The issue came from a SQL update script that hadn't been run when the upgrade process thought it had. He includes the two SQL statements you'll need to run to fix the problem.

tagged: serendipity upgrade gotcha

Link:

Developer Tutorials Blog:
Migrating legacy PHP 4 applications to PHP 5
Jul 10, 2008 @ 12:56:41

In a new post to the Developer Tutorials blog Akash Mehta takes a look at migrating PHP4 applications up to the more recent versions of PHP5.

PHP 5 supports most of the legacy syntax features of PHP 4. Most code written for PHP 4 should function fine under PHP 5, and a comprehensive test suite could check this. However, many of the backwards-incompatible changes in PHP 5 were in regard to language quirks, and quite a few hacks rely on these in order to function.

He points out some of these hacks including changes to the object model and updates to the way variables are handled (breaking many "bad use" cases). He also points out the changes made in the latest Windows binaries as well as some of the new reserved keywords that could conflict with pre-existing code in your application.

tagged: migrate application php4 php5 legacy upgrade gotcha

Link:

Eirik Hoem's Blog:
Array problems with SOAP and PHP - Updated
Mar 13, 2008 @ 15:22:19

Eirik Hoem has posted an update on a previous problem he was having when working with SOAP in PHP and its handling of arrays.

The scenario was that when an array with only one object was returned over SOAP the array was discarded and pointed straight to the single object.

Come to find out, this behavior wasn't a bug, it was a feature - the fix is to add another parameter to the initialization of the SoapClient to add the SOAP_SINGLE_ELEMENT_ARRAYS feature.

tagged: soap gotcha array problem soapsingleelementarrays feature bug

Link:

PHPEverywhere:
Octopussy numbers in PHP
Feb 01, 2008 @ 15:21:00

John Lim has posted about an interesting bug he's come across when working with the output of two strings that should look the same:

Someone reported a bug in ADOdb, the open source db library i maintain. I went crazy for half an hour until i realised the problem.

According to him, "if you expect the above code to produce the same values, you are sadly mistaken". His example gives an interesting result for the first echo statement - not echoing the 9 in the first character like it seems would make sense. Check out his post for the code and try it out for yourself.

tagged: number echo adodb database gotcha

Link:

David Coallier's Blog:
PHP Namespaces (Part 1: Basic usage & gotchas)
Aug 20, 2007 @ 20:12:00

David Coallier has posted his look at the namespace support that will be included with PHP6, specifically some examples of their basic usage and things to look out for when using them in your applications.

Well, PHP has namespaces now! Time to start educating people on that long awaited feature and for the people that already do know namespaces from C++, you also need to read this, it's simple, but will give you the basic syntax.

He starts with things like "what is a namespace?" or "what are they used for?" before getting into the syntax. The next step up is explaining how they work - he uses an example project, ProjectOne, with its namespace definition and an example script (invoke.php) that uses this class (including the new "import" keyword and the double-colon namespace separator).

tagged: namespace basic usage gotcha definition example namespace basic usage gotcha definition example

Link:


Trending Topics: