 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Mike Purcell's Blog: PHPUnit - Upgrade - Convert assertType to assertInternalType
by Chris Cornutt May 21, 2012 @ 09:56:59
In this quick post to his blog, Mike Purcell mentions the deprecation of the "assertType" assertion and includes some code you can add to correct the issue in your tests.
We recently upgraded phpunit from a very old version to the current 3.6.x version (at time of writing). During the upgrade I noticed that assertType is no longer supported in many of our tests which were testing if something was a string, an array, or an object. So I had to write a quick script to update assertType to assertInternalType and figured I would post it for others if they needed to do the same.
The code goes into each of your tests (recursively) and finds the places where the "assertType" assertion is used and replaces it with its newer cousin "assertIntrnalType".
voice your opinion now!
phpunit unittest asserttype assertinternaltype string replace
PHPMaster.com: Practicing Regular Expressions with Search and Replace
by Chris Cornutt November 23, 2011 @ 14:27:59
On PHPMaster.com today there's a new tutorial that shares a few regular expression tips about doing some search and replace in your content.
So how can you practice using regex if you are limited to just using them in your code? The answer is to use a utility, of which there are many, that uses regex for performing search and replace. I'm sure everyone is familiar with the standard "find x and replace it with y" type of search and replace. Most IDEs and text editors have built in regex engines to handle search and replace. In this article I'd like to walk through a series of exercises to help you practice using regex.
His examples are based on Netbeans but can be used in just about any IDE that supports regex (or even just your code). He shows how to match word boundaries, do some grouping, work with back references and doing some search/replace based on multiple groupings.
voice your opinion now!
regular expression practice search replace boundaries group backreference
PHPBuilder.com: PHP Simple HTML DOM Parser Editing HTML Elements in PHP
by Chris Cornutt September 08, 2011 @ 10:06:07
On PHPBuilder.com today there's a new tutorial from Vojislav Janjic about using a simple DOM parser in PHP to edit the markup even if it's not correctly W3C-formatted - the Simple HTML DOM Parser
Simple HTML DOM parser is a PHP 5+ class which helps you manipulate HTML elements. The class is not limited to valid HTML; it can also work with HTML code that did not pass W3C validation. Document objects can be found using selectors, similar to those in jQuery. You can find elements by ids, classes, tags, and much more. DOM elements can also be added, deleted or altered.
They help you get started using the parser, passing in the HTML content to be handled (either directly via a string or loading a file) and locating elements in the document either by ID, class or tag. Selectors similar to those in CSS are available. Finally, they show how to find an object and update its contents, either by adding more HTML inside or by appending a new object after it.
voice your opinion now!
simple html dom parse tutorial selector find replace edit
Bence Eros' Blog: Life without static in PHP
by Chris Cornutt December 20, 2010 @ 13:17:03
In this new post to his blog Bence Eros shares some of the frustrations and issues he's had when dealing with static methods and properties in his applications and how, with a bit of re-engineering, you might be able to have "life without static".
The problem with static members in PHP is the poor initialisation capabilities. The initial value of a static property can only be a literal or a named constant. [...] The same problem exists for non-static properties too, but the constructor is a dedicated place to initialize non-static properties. But since we don't have Java-like static constructors in PHP there is no place to do static property initialization. In a lot of cases people do it by putting the assignment statements after the body of the class, but this method is very ugly.
An alternate method he suggests is using a singleton to initialize and grab the value of a class value. He gives some sample code to show how it might be done, but warns that it might not be the right way to do things. It has "significant disadvantages" that could cause trouble down the road (for one, singletons make it difficult to unit test).
voice your opinion now!
static class tutorial singleton replace
Seldo.com: PHP needs to die. What will replace it?
by Chris Cornutt October 06, 2010 @ 12:19:40
In this recent post Laurie Voss has voiced his opinion about the PHP language - that it needs to die, but also asks what should replace it.
The reason I know PHP has to die is because I've seen this before. Roughly a decade ago, PHP killed Perl. [...] As a language for newcomers, and especially for web developers, it was already dying in 1999 and was mostly dead by sometime around 2005. [...] There was no reason you couldn't write a perfect web app in Perl, but in PHP you'd do it faster and easier, despite the flaws in PHP itself which were, even then, already obvious.
He talks about moving on from PHP, why almost requiring a framework to do anything these days is a bad thing and how, despite the flaws the language has, he feels "trapped in a language that's losing its suitability for the task." He suggests that one successor might be Ruby on Rails but also points out some of the flaws it has including performance, Active Record and possible issues with code generation. He notes, though, that this isn't quite the replacement he had in mind and that there's just not something there to fill that gap.
Be sure to read the comments for lots of great opinions from both sides of the PHP opinion fence.
voice your opinion now!
opinion replace language rubyonrails
Andrey Hristov's Blog: Replacing mysqli's Connection, Result and Statement classes
by Chris Cornutt July 09, 2010 @ 10:31:03
On his blog today Andrey Hristov has a quick post that talks about two methods to extend the functionality that the mysqli extension offers in PHP with your own custom code.
Have you ever though about extending mysqli's classes. It's pretty simple to subclass the connection class mysqli. However, subclassing mysqli_result and mysqli_stmt is not so obvious, actually I though that it's even not possible. However, never say never! After discussing mysqli's OO interface for an hour yesterday [...] I found out how one can plug his own classes.
Two code examples are provided - one for extending the mysqli_result and the other extending the mysql_stmt class. You can find more about these and other classes the mysqli extension has to offer in this section of the PHP manual.
voice your opinion now!
replace mysqli connection result statement class extend
Noupe.com: Getting Started with PHP Regular Expressions
by Chris Cornutt August 24, 2009 @ 07:59:10
Noupe.com has posted a new guide to getting started with regular expressions in PHP. Regular expressions can be one of the most powerful tools at your disposal when used correctly.
The main purpose of regular expressions, also called regex or regexp, is to efficiently search for patterns in a given text. These search patterns are written using a special format which a regular expression parser understands.
They cover some of the basics - special characters and some examples using them (like $, d, and *) - before getting into the preg_* functions in PHP. They also include some handy examples to validate things like US zip codes, email format validation and removing duplicated words in a section of text.
voice your opinion now!
regular expression tutorial preg
|
Community Events
Don't see your event here? Let us know!
|