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

Reddit.com:
Is there anything wrong with using functions?
August 07, 2013 @ 11:39:47

In a largely object-oriented world, one Redditer asks if it's still okay to just use functions, the more procedural method of PHP development:

Is there anything wrong with using an include file of functions instead of using full code in a file? [...] Obviously you wouldn't write functions for one off tiny things, but I think it would help to read files altogether especially if the functions file was alphabetically listed.

There's several suggestions in the comments including things like:

  • You should also look into using a templating engine, so you can separate your html from your php code.
  • One thing you could always ask yourself is "Do I will ever need to write that part a second time somewhere else ?" If "yes", that means you should put that part in a function.
  • Before you go writing a load of functions and putting them all in a file, which can get quite unmanageable, consider grouping them logically and placing them in classes.
  • Function names should start with a verb though (except for trivial getters whose meaning is clear by context, which can be named after the thing they get).
  • Do group them logically, but it's not necessary to place them in a class unless they share data or state.
0 comments voice your opinion now!
oop functions procedural opinion file group

Link: http://www.reddit.com/r/PHP/comments/1jss6q/is_there_anything_wrong_with_using_functions

Jani Hartikainen:
Parsing and evaluating PHP in Haskell Part 2
January 23, 2013 @ 11:24:34

Jani Hartikainen has posted the second article in his series looking at parsing PHP with Haskell (part one is here). In this new article he builds on the parser he built last time and gets to the actual evaluation of the PHP code.

Last week I wrote a post about a PHP parser / evaluator I wrote in Haskell. I explained some of the parts on how the parser itself was designed to process PHP code into an abstract source tree. Continuing from where we left off in the previous part, in this post I'll discuss the actual evaluation part.

He starts by introducing the structure of the evaluator script, how it's broken up into functionality based on the type of object/data type being handled. He uses a "custom monad transformer stack" to handle the environment for the evaluation as is progresses. He talks about handling statements and expressions, declaring custom functions and the actual execution of the function call. There's also a mention of handling conditionals/looping as well as dealing with PHP's type juggling.

if you're interested in seeing the final result (and maybe trying it out for yourself) you can find the full source on Github.

0 comments voice your opinion now!
haskell parse evaluate monad transformer functions expressions looping typejuggling


PHPRefresh.com:
Managing Sessions and State with PHP
January 11, 2013 @ 10:25:15

In this new tutorial on the PHPRefresher.com site, Anand Godar walks you through just about all of the session functionality that comes with PHP and includes some code snippets for explanation.

Due to the fast evolution of Web programming, the stateless nature of the HTTP protocol brought many problems to certain Web applications that required maintaining their state across several HTTP requests. This demanded a rapid development of several mechanisms aimed at tackling this issue through diverse methods. Then a session management emerged as a direct response to the above mentioned problem, and currently this mechanism is being used by PHP developers worldwide, in cases where a Web application needs to keep track of its "state" during the occurrence of different HTTP requests.

The article starts off with the basics of sessions - what they are, how they're handled and created by PHP - and moves into the specific functions and their use. He talks about starting/ending sessions, their IDs, caching, module handling and working directly with the session cookie (if it exists).

0 comments voice your opinion now!
session tutorial introduction functions


Nexen.net:
PHPInfo() Stats - Part 2
November 21, 2006 @ 10:51:00

Damien Seguy has continued his series looking at PHP configurations around the web and is sharing the results in the form of two new reports over on Nexen.net.

I just published the second part of the serie about PHP configurations. This part focuses on three aspects of PHP: PHP extensions, PHP streams, and disabled functions.

You can find the statistics themselves here and the latest configuration statistics here. It's interesting to see the drop-off when it comes to the various modules that are installed ("php, ftp and http are the most common. Besides them, tough luck.") and to see the somewhat more gradual curve of which functions are disabled - with system() topping out the list (with good reason).

0 comments voice your opinion now!
phpinfo statistics streams extensions pecl disabled functions graph phpinfo statistics streams extensions pecl disabled functions graph


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


Jacob Santos' Blog:
Global Functions and How to Not Use Them
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.
0 comments 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)
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.

0 comments 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
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).

0 comments 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
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.

0 comments 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
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.

0 comments voice your opinion now!
maintaining state advanced functions mysql storage tutorial maintaining state advanced functions mysql storage tutorial



Community Events





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


laravel testing interview framework developer unittest podcast configure threedevsandamaybe refactor opinion code symfony2 language community introduction release install series list

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