 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
DevShed: Classes as PHP Functions
by Chris Cornutt 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.
voice your opinion now!
classes functions methods properties tutorial part2 classes functions methods properties tutorial part2
Jacob Santos' Blog: Global Functions and How to Not Use Them
by Chris Cornutt August 08, 2006 @ 06:26:32
In his latest post, Jacob Santos talks about global functions and some of the dangers behind using them in your code (as per his own experience debugging with them in place).
When I develop in PHP and code functions, I always either place them in a file or place them at the top of the script. Well, this is more about C++ and how I totally freaked out my teacher, by breaking his paradigm of thought. You see, you can have a definition of a function at the top of the page and then code the body of the function later.
He soon discovered his problem in debugging the script - he was too used to having the global functions at the top (as in C++) and not mixed in with the code - or at the bottom of the script.
If there is something at least somewhat common about popular scripts that people use and extend, is that the functions are placed in organized manner. Reforming otherwise is a bitch and I remember rewriting the entire script anyway. You can't reform when you can't reuse anything.
voice your opinion now!
global functions using badly location debugging global functions using badly location debugging
Greg Beaver's Blog: phpDocumentor and __get/__set/__call - give us your ideas (RFC)
by Chris Cornutt July 14, 2006 @ 06:06:00
In his latest post today, Greg Beaver is also taking a look at phpDocumentor and some of the documentation methods it allows, noting that providing the right notes on the "magic" functions has always been a point of difficulty.
One of the trickier feature requests for phpDocumentor has been documenting "magic" object properties and methods. By "magic" I am referring to properties and methods that are created dynamically by PHP 5.0+ userspace class methods __get, __set, __isset, __unset and __call.
He gives a code example of creating properties and a magic function (borp). To illustrate his point, he tries to specify the phpDocumentor format that would go with it - not an exact match, but with the help o ffour new tags it's made easier: @property, @property-read, @property-write, and @method.
voice your opinion now!
phpdocumentor __get __set __call ideas magic functions property phpdocumentor __get __set __call ideas magic functions property
JellyandCustard.com: Regular Expressions in PHP
by Chris Cornutt June 22, 2006 @ 07:03:06
In a post from JellyandCustard.com, there's an inside look at regular expressions in PHP - how to use them and what they are.
Regular Expressions (regex for short) appear to a lot of people as the 'black art' of coding. Most languages, be it PHP, Java, C, .NET, VB etc have a way of using regular expressions - and they can certainly make your job easier. So lets start on our journey into regular expressions. I am by no means an expert, but hopefully I'll be able to clear the fog that surrounds regular expressions!
He mentions the functions to use and provides a simple example of matching a phone number (US format). They take the regular expression string and break it down into its pieces, explaining how each one works (and relates to the other parts of the expression). They also provide a brief "cheat sheet" of some of the other special characters (including common uses on some).
voice your opinion now!
regular expression introduction tutorial functions examples regular expression introduction tutorial functions examples
DevShed: Adding Methods to the Query Processor in PHP
by Chris Cornutt May 24, 2006 @ 12:15:43
DevShed has posted the second part of their "Network Programming in PHP" series today - this time, they enhance the QueryProcessor class they've developed with even more functionality.
At this point I guess that all the networking PHP built-in functions that I covered in the first article, such as the "gethostbyaddr()", "gethostbyname()", "gethostbynamel()" functions are already familiar to you. So now I will explain what new things you'll learn in this second article of the series. Since I want to continue expanding the "QueryProcessor" class that I coded previously, this installment will focus on adding more methods to it, by using other useful PHP network functions, aimed particularly at running popular Windows networking applications, like "ipconfig," "netstat" and more.
If you didn't get a change to check out part one, it's definitely suggested that you do so before you start on this section. As mentioned, they're going to show you how to add other functionality to the class, including the ability to ping another server, check the current machine's network settings, perform a "netstat" command, and get the MX records for a hostname. At the end, they stick it all together in the complete (so far) class for easy cut and paste.
voice your opinion now!
part2 network functions query processor part2 network functions query processor
DevShed: Using Advanced Functions to Maintain the State of Applications with PHP Sessions
by Chris Cornutt May 04, 2006 @ 08:00:56
DevShed continues their "Managing the State of Applications with PHP Sessions" with this new tutorial, part two looking at the more advanced features that PHP has to offer to developers working with sessions.
This is part two of the series "Maintaining the state of applications with PHP sessions." In three parts, this series ranges from the basics of session management in PHP, such as creating, registering session data, and destroying sessions, to exploring advanced concepts, like working with different session storage modules and creating custom session handling objects.
In this article I'll take a look at them, in order to demonstrate with several code samples how to use them and how to take advantage of their many capabilities. Hopefully, when you finish reading this article, you should have a decent understanding of how to include advanced session handling routines within your own PHP-driven applications.
They start with the introduction to the session_set_save_handler function, making it simple to adjust how your script deals with sessions. This sets the stage for the next step in the tutorial - the creation of a MySQL handling system to store the visitor's session data. They wrap it all up with the code for the MySQL functions you'll need to get it all working, including handlers for saving, updating, and removing the session data that's in place.
voice your opinion now!
maintaining state advanced functions mysql storage tutorial maintaining state advanced functions mysql storage tutorial
DevShed: Introduction to Maintaining the State of Applications with PHP Sessions
by Chris Cornutt April 27, 2006 @ 07:03:05
DevShed has posted a tutorial that talkes about a simple way to keep track of user information (or any other info) as a user navigates your site - using PHP sessions.
In PHP, session management is used to help web applications maintain their state across several HTTP requests when needed. In this first part of a series, you will learn the basics of the PHP built-in session mechanism, as well as some of its many useful functions.
Since PHP sessions are one of those things that sooner or later you must learn as a PHP developer, in this article I shall provide an overview of them. I will begin with the basics of how to use them, highlighting their strong points and weaknesses, and finally explore some of their most advanced concepts. By the end of this series, you should have all the knowledge that you need to start using the most common PHP session management functions, so you can use them during the development of your own applications.
They explain the basics of sessions and how they can be used in your apps, how to destroy a session, some of the variou ssession functions, and how you can configure your sessions and session hander to fit your needs.
voice your opinion now!
sessions application state introduction functions basics configuration sessions application state introduction functions basics configuration
Christian Stocker's Blog: Calling PHP function from XSLT vs. native XSLT functions benchmark
by Chris Cornutt March 27, 2006 @ 06:55:47
One of the more underused thechnologies to come along these days is XSLT - that powerful langauge to style XML documents in a simple, "more correct" kind of way (seperation of data and layout). Most languages have support for this combination, including PHP - but what's the best way to combine PHP and XSLT? Christian Stocker took a look in this new post on the Bitflux blog.
After Rob's idea from yesterday about using XMLReader within XSLT I was wondering, how much of a slowdown calling PHP functions from XSLT is.
I wrote 4 different XSLT templates, which do a simple substring. One with the xslt function "substring", one with just calling the native PHP function "substr" and one with calling a user-defined function (which is also just calling "substr"). I called this 100 times (with one of those great recursive self-calling xslt-templates) and did call the "transformToXML" function a 100 times for each stylesheet. This means, we called the function 10'000 times for each benchmark run.
His bases the results off of a sample with no function call at all and, but running it through 100 times, came up with results that weren't all that surprising. In order of speed, the ranking (shortest time first) was: no call, xslt only, php native, and php userland. Using the PHP functions from inside of XSLT made the test quite a bit slower, but, as he notes, most users won't be running recursions of 100 each time they run a script.
voice your opinion now!
XSLT native functions user-defined substring substr XSLT native functions user-defined substring substr
|
Community Events
Don't see your event here? Let us know!
|