News Feed
Sections




News Archive
feed this:

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

PHPMaster.com:
Say Hello to Boris A Better REPL for PHP
April 02, 2013 @ 10:34:00

On PHPMaster.com today Shameer C has a new tutorial introducing you to Boris, a REPL (read-eval-print loop tool) that's a bit more enhanced than the basic PHP interactive shell.

As web developers, we know the importance of the JavaScript console provided by the browser in testing out code snippets. We don't need to write an entire HTML page and JavaScript code just to verify the functioning or logic of a small routine we wrote. Instead, we simply run the expressions in the console and immediately see the results. Similarly, a REPL (Read-Eval-Print Loop) is the console of a programming language in which we can write code line-by-line and see what it does. [...] PHP's REPL is very good in what it does, although it does have some limitations. [...] And so, Boris tries to solve these problems and other concerns as well.

He walks you through the installation (via a git clone and, later, through Composer) and shows how to run it as well as some sample output. He also shows how to make a custom command-line Boris runner and how to embed it into your application. His example of a tool that would benefit from this is a command-line web service client using Boris and Guzzle.

0 comments voice your opinion now!
boris repl read eval print loop tool commandline github


PHPMaster.com:
Learning Loops
December 15, 2011 @ 10:15:00

PHPmaster.com has a new introductory tutorial for those just starting out with PHP (or with programming really) talking about using looping structures for sets of data - for, while/do-while and foreach.

A significant advantage of computers is that they can perform repetitive tasks easily and efficiently. Instead of writing repetitive code you can write a set of statements that processes some data and then have the computer execute them repeatedly by using a construct known as a loop. Loops come in several different flavors in PHP: for, while, do-while, and foreach. I'll introduce you to each of them and show you how they can making repetitive tasks straightforward and easy to maintain.

The tutorial explains a use case for each of the loop types and includes a bit of sample code showing how to put it into practice. It also shares two special keywords that can be used to bypass or break out of your current loop - break and continue.

0 comments voice your opinion now!
introduction tutorial loop dataset for while foreach break continue


Gareth Heyes' Blog:
Non alphanumeric code in PHP
September 23, 2011 @ 10:05:47

Gareth Heyes has tried out an interesting experiment - running non-alphanumeric code in PHP using only octal escapes.

So a small php shell was tweeted around and it inspired me to investigate a way to execute non-alphanumeric code. First off I started with the idea of using octal escapes in PHP and constructing the escape so for example: 107 is "G" if I could construct the "107" and add the backslash to the beginning maybe I could construct "G".

A snippet of example code is included showing his octal-based code for creating a "G" (6 lines of pluses, parentheses, equals and a few more characters). By doing some trickery with bitwise operators on strings, he was able to combine characters and make the string "GET". Pretty clever, even if it's not entirely practical.

0 comments voice your opinion now!
nonalphanumeric code shell loop octal


NETTUTS.com:
Quick Tip Loop Through Folders with PHP's Glob()
April 27, 2010 @ 11:49:15

Sometimes when you're looking through the filesystem in your PHP application, you just need a quick and easy way to grab a file listing from a directly and move on. Sure, you can use the usual opendir and readdir combo to loop through the files, but there's another function that might suit your needs better - glob. In this quick tutorial from NETTUTS.com today they show you how it works.

Are you still using opendir() to loop through folders in PHP? Doesn't that require a lot of repetitive code everytime you want to search a folder? Luckily, PHP's glob() is a much smarter solution.

They include code examples showing how the usual opendir/readdir code can be translated over to an example using glob and mention the two arguments you can use - a pattern-matching search string and a modifier to change settings on the search and on the results returned.

0 comments voice your opinion now!
glob tutorial loop filesystem opendir readdir


PHPBuilder.com:
Loops & Decisions in PHP - The ABC's of PHP Part 8
May 07, 2009 @ 10:26:34

PHPBuilder.com has posted the eighth part of their introductory "ABCs of PHP" series today. This time the focus is on looping and decision functionality (like if/while/for/etc).

n any given computer language (PHP is no exception) there has to be a way to allow the running code to decide between doing 2 different things. If there wasn't then software would not be able to adapt based on operating conditions, or it wouldn't be able to decide between two different users.

They look at using: if statements and operators, for loops and while loops. When they look at the operators, they talk about the differences between equals/not equals, grater than/less than and two of the boolean operators - AND and OR.

2 comments voice your opinion now!
loop decision if while for operator tutorial introduction beginner


Jani Hartikainen's Blog:
Closures coming in PHP 5.3 and that's a Good Thing
February 20, 2009 @ 14:05:56

Jani Hartikainen takes a look at closures in a new post to his blog - why their good and why they can help you more than you know.

PHP 5.3 will be introducing closures to PHP. Closures, also known as anonymous functions, will allow you to declare functions "inline" and store them in variables. While the syntax may seem a bit weird compared to how it is in languages like JavaScript, closures will be a useful addition to the language. However, like reflection, it's a feature that may not immediately show it's usefulness...

He explains what they are (a sort of anonymous function) and a simple example of them in use - a function that works with data from an array to display each of the rows with the given "formatter" function. Another brief example is a method of using them in PHP functions like array_map and usort as an argument for the callback parameter.

0 comments voice your opinion now!
closure php5 good anonymous function example row loop callback


Leonid Mamchenkov's Blog:
Perl vs. PHP variable scoping
December 12, 2008 @ 08:49:14

Leonid Mamchenkov has compared Perl versus PHP in this new blog post - specifically how they handle variable scoping.

I've mentioned quite a few times that I am a big fan of Perl programming language. However, most of my programming time these days is spent in PHP. The languages are often similar, with PHP having its roots in Perl, and Perl being such a influence in the world of programming languages. This similarity is often very helpful. However there are a few difference, some of which are obvious and others are not.

His example compares looping (a foreach in both) and how, after the Perl loop the $value variable is no longer accessible. In PHP, however, it's passed back out into the current scope and can be read just like any other variable. While this can be useful, it can also cause headaches when trying to track down elusive bugs.

1 comment voice your opinion now!
variable scope foreach loop local outside compare


PHPEverywhere:
Simple Easy Parallel Processing in PHP
September 10, 2008 @ 09:33:51

John Lim has a new blog post today sharing his method for simulating parallel processing inside of a PHP application.

One problem we were having is that some of our batch processing jobs were taking too long to run. In order to speed the processing, we tried to split the processing file into half, and let a separate PHP process run each job. Given that we were using a dual core server, each process would be able to run close to full speed (subject to I/O constraints).

He shows the two "jobs" files that just echo out the job name and the number of seconds it's been running and the "control.php" that makes use of streams (pointed at localhost) to start the jobs apart from the main script. Another function checks the stream resource to see if it gets an EOF from it and returns back the output.

0 comments voice your opinion now!
parallel processing tutorial stream job loop eof


Daniel Cousineau's Blog:
Displaying N-Deep Trees (Remember Your Algorithms Course?)
August 07, 2008 @ 12:03:23

On his Tower of Power blog Daniel Cousineau has written up a look at using a more detailed categorization method than just a parent/child relationship on your data - Tree Traversals.

If the software calls for only 2 levels of categorization (Parent and Child only), a simple nested for loop will suffice. However, software requirements change and you'll soon find yourself up shit creek without a paddle if you need to support 3 or 4 levels of nesting. [...] To those who's training is less formal (most web developers I meet have practical training, not formal), I'll help you out: Tree Traversals (or if you are completely lost, Recursion).

He creates a recursive function that, when passed in a category set with different types in it, can handle each of them and then calls itself again with the new child data. His sample code creates url out of a set of categories.

0 comments voice your opinion now!
tree category recursion tutorial parent child loop treetraversal


Stefan Mischook's Blog:
Note to CodeIgniter nerds please, no looping code in your views.
June 06, 2008 @ 08:43:53

Stefan Mischook so eloquently expresses his opinion on a method for looping in the CodeIgniter framework in this new post to the KillerPHP blog today, "Note to CodeIgniter nerds: please, no looping code in your views."

I was researching things 'nerd' on the Web today, and I found myself at the CodeIgniter website. [...] I'm wondering about CodeIgniter's decision to place PHP looping code in their views.

He notes that the whole point of the View in the Model/View/Controller framework is to keep as much PHP out of it as possible. In their example they show just the opposite. Some of the comments agree with his post, noting that this is in fact the point of the View. Others, however, point out that code in the View, especially looping code is something necessary to output multiple items being passed out.

0 comments voice your opinion now!
codeigniter view framework loop output



Community Events





Don't see your event here?
Let us know!


framework introduction symfony interview deployment bugfix series language opinion community library laravel zendserver podcast conference release api developer tips list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework