News Feed
Jobs Feed
Sections




News Archive
feed this:

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

SitePoint PHP Blog:
Getting Started with PHP Underscore
April 17, 2014 @ 13:50:28

The SitePoint PHP blog has a new article posted showing you how to get started with Underscore, a PHP library ported over from Javascript's popular Underscore.js library with many of the same methods intact.

If you've ever used the Backbone framework for JavaScript, you'll already be familiar with Underscore. Indeed, it's become incredibly useful for JavaScript developers in general. But did you know that it's been ported to PHP? [...] Underscore describes itself as a "utility belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It's the tie to go along with jQuery's tux, and Backbone.js's suspenders."

He starts by showing you how to get it installed and some of the basic syntax of the methods it defines (basically replace the period with the double-colon) for both the procedural and OOP handling. He shows examples of a few of the more handy methods it provides including:

  • Each
  • Pluck
  • Minimum and Maximum
  • Filter and Reject
  • sortBy
  • groupBy

...and many more. There's also a bit of talk about templating and extending the library via "mixins".

0 comments voice your opinion now!
underscore port introduction methods functionality

Link: http://www.sitepoint.com/getting-started-php-underscore/

NetTuts.com:
Reflection in PHP
April 19, 2013 @ 10:24:28

On NetTuts.com today there's a new tutorial talking about a part of PHP that can be quite powerful but isn't used too often - reflection in PHP. Using Reflection you can get information about your actual code and its elements without having to try to parse it yourself.

Reflection is generally defined as a program's ability to inspect itself and modify its logic at execution time. In less technical terms, reflection is asking an object to tell you about its properties and methods, and altering those members (even private ones). In this lesson, we'll dig into how this is accomplished, and when it might prove useful.

They provide a little context around the idea of "reflection" in programming languages and then jump right in with a few sample classes. They set up their "Nettuts", "Manager" and "Editor" classes and show how to use the ReflectionClass functionality to get their structure. The examples show how to get the class' methods, their properties and calling these methods using things like invoke and call_user_func.

0 comments voice your opinion now!
reflection tutorial introspection methods parameters invoke

Link: http://net.tutsplus.com/tutorials/php/reflection-in-php

Lorna Mitchell:
9 Magic Methods in PHP
December 11, 2012 @ 12:18:49

Lorna Mitchell has a new post showing nine of the magic methods that are included in PHP by default (like __construct, __get and __set) including a few you may not have used before.

The "magic" methods are ones with special names, starting with two underscores, which denote methods which will be triggered in response to particular PHP events. That might sound slightly automagical but actually it's pretty straightforward, we already saw an example of this in the last post, where we used a constructor - so we'll use this as our first example.

She includes details (and some code samples) for these methods:

  • __construct
  • __destruct
  • __get
  • __set
  • __call
  • __sleep
  • __wakeup
  • __clone
  • __toString

You can find out about these and a few others in this page of the PHP manual.

0 comments voice your opinion now!
magic methods oop introduction beginner tutorial


Reddit.com:
Avoid static methods at all costs? (testability)
September 26, 2012 @ 11:59:04

On Reddit.com there's a recent post questioning the (recently) common saying that PHP developers should avoid static methods when concerned about testability:

I get it: testing is important, and building your codebase in a manner that is easy to test should be a priority. However, sometimes I feel like I have to compromise on the elegance of my code in order to maintain testability. Cases where perhaps a static method makes sense, but end up having to perform some coding acrobatics in order to avoid it. Is this a common challenge, something many developers face and must balance between? Or am I misguided in how frequently static methods can be the most elegant solution (before taking testability into consideration)?

Answers point out a few things - that sometimes, state doesn't matter and static is okay or that they can be used if the instance they return is always exactly the same, never altered.

0 comments voice your opinion now!
static methods unittest testability opinion


Volker Dusch's Blog:
An introduction to PHPUnits @covers annotation
November 04, 2011 @ 09:55:32

PHPUnit is one of the most widely used unit testing tools for PHP applications. It comes packed with features, some that are commonly used and some not so much. In a new post to his blog today Volker Dusch looks at one specific feature - the "@covers" annotation you can use in your tests' comments to specify which functionality you're actually testing.

One of the goals of your test suite and the coverage report is to make you trust in your code base and to remove the fear of changing something that needs to be changed. [...] You shouldn't think "Well yes that a 100% but a lot of that just comes from that big integration test and I don't know if the class is really tested!". [...] Thankfully PHPUnit offers a way to drastically increase your confidence in what you actually have tested.

Using the "@covers" annotation on your test method docblocks gives you one more level of confidence in what's being tested and can help make for clearer updating down the road. He also mentions using them to provide extra insight into protected methods in your code and where the test coverage for them really lies.

0 comments voice your opinion now!
phpunit covers annotation protected methods codecoverge


Alexander Netkachev's Blog:
Practical PHP events
October 24, 2006 @ 07:20:48

In his latest tutorial, Alexander Netkachev shows how to, with some of the simple PHP functions, create an event system for your script, complete with callbacks.

The way how events are raised and how listeners are attached on the events is a part of a core in many modern applications. It plays an important role in some enterprise design patterns (MVC, for example).

He starts with the basics of event handling - some of the terms and descriptions of basic functionality that any good event handler would have. He describes the most common setup of an event-interaction relationship. Then, it's on to the code, showing first three different ways to call functions (by name, by variable, and by callback).

He finishes it off with a functional example that responds to a a call to fireEvent (five times) and handles each by calling the function in the callback information (myFunction).

1 comment voice your opinion now!
event handline callback tutorial basics calling methods event handline callback tutorial basics calling methods


DevShed:
Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP
September 18, 2006 @ 08:21:51

DevShed continues its look at the DirectoryIterator functionality in PHP5 with the second part of the series today - "Finding Paths, Timestamps and More with the DirectoryIterator Class in PHP".

Are you interested in having at your disposal a quick reference for working with the "DirectoryIterator" class that comes with PHP 5? Then this might be the article that you've been waiting for! Welcome to the second tutorial of the series "A Close Look at the DirectoryIterator Class in PHP 5." Over the course of this set of installments, you'll find complete coverage of the most important methods bundled with this class, and learn how to take advantage of their excellent functionality.

They cover even more functions in this part:

  • rewind, current, valid
  • getFileName, isFile
  • getMTime, getATime, getCTime
  • getPath, getPathName
Each set is supported by code and explaination to help introduce their concepts in a useful way.

0 comments voice your opinion now!
tutorial directoryiterator methods part2 path timestamp file tutorial directoryiterator methods part2 path timestamp file


DevShed:
Classes as PHP Functions
August 09, 2006 @ 05:49:25

Continuing on in their "PHP functions" series today, DevShed has posted this next step up the ladder, getting more advanced with the functions they're working with. This time, there's a focus on functions inside classes and creating the classes around them (a sort of introduction to object-oriented programming).

Continuing our PHP functions article, we move on to creating classes. Let me say right at the start that you can write perfectly effective and useful PHP code without creating classes or going into object oriented programming. Object oriented programming can be very powerful and PHP programmers are increasingly taking advantage of these capabilities, which have been greatly expanded since PHP4.

They start with the creation of a simple class - a human class with two $legs and two $arms. They show a simple display of this data and add another attribute to the class, one for hair color. They then capture the output they've been creating inside a function, report, and show how to execute it. Finally, they show how to use the special function that runs when the object is created - the constructor.

0 comments voice your opinion now!
classes functions methods properties tutorial part2 classes functions methods properties tutorial part2


DevShed:
Implementing Additional Methods with mysqli and PHP 5
July 10, 2006 @ 07:22:54

DevShed has posted part three of their popular "using mysqli in PHP5" series today, this time, they focus on increasing the functionality of the code they started last time with other mysqli methods.

I must say that the "mysqli" extension offers an impressive set of features, which can be implemented right from the very beginning. However, and speaking of its cool features, in the next few lines, I'm going to show you a few more. Over the course of this last tutorial, I'll be covering some other methods and properties, mainly aimed at finding the IDs after inserting new rows, and obtaining information about specific table fields.

They touch on the fetch_array, data_seek, fetch_assoc, fetch_field, and fetch_seek functions, giving examples and other assicated properties along the way.

0 comments voice your opinion now!
mysqli mysql additional methods php5 tutorial mysqli mysql additional methods php5 tutorial


Ben Ramsey's Blog:
Add Children with SimpleXML
May 11, 2006 @ 20:03:57

In this new post on Ben Ramsey's blog today, he shares his experiences with SimpleXML, mentioning specifically some of the undocumented functions that he's noticed.

I was very excited today while glancing through the code in ext/simplexml/simplexml.c to find some, as of yet, undocumented methods in PHP's SimpleXMLElement class. This discovery came after I've spent several hours over the last couple of nights banging my head against the desk to figure out a way to create a class that extends SimpleXMLElement and adds a new method for adding a child, which would have to use DOM in order to work-or so I thought.

Of course, it's wasn't as easy as it seemed, and Ben soon found some of the limitations of the SimpleXML library. Of course, he did manage to find a way to add new children to the document you're working with (something that normally would have required the intervention of the DOM functionality). Check out the post for a code example.

1 comment voice your opinion now!
simplexml add children undocumented feature methods dom xml simplexml add children undocumented feature methods dom xml



Community Events











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


symfony2 introduction component install release podcast language facebook composer opinion framework application overview package hack unittest security code threedevsandamaybe hhvm

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