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

Rob Allen:
Global installation of PHP tools with Composer
December 23, 2013 @ 09:39:13

Rob Allen has a quick post today showing how to use Composer to globally install tools and libraries on your system.

The Composer package manager along with the Packagist repository site is quickly becoming the defacto PHP package management system. One feature I found out about recently is that you can install packages globally rather than locally into your project. I think that this is most useful for development tools, such as PHPUnit which are then available everywhere.

He includes the command syntax you'll need to do the global install, showing an example with the popular PHP unit testing tool PHPUnit. There's also a "global update" command you can use to update these packages (or add more) later on too.

0 comments voice your opinion now!
global install tools composer example command

Link: http://akrabat.com/php/global-installation-of-php-tools-with-composer/

Easybib Blog:
Extending Composer
October 07, 2013 @ 12:20:41

In this recent post to their site, Easybib shares a presentation and the answers to some questions about extending Composer, the popular package management tool for PHP.

Composer is one of the core tooling we use at EasyBib when we work on the various products for the company. [This] deck of slides is from a talk I gave at the Berlin PHP Usergroup meetup in November. [...] In addition, there were a few questions how dependencies are handle in a project when installed through composer's global command.

They answer questions about loading global vendors (and what should/shouldn't be installed this way) as well as which one wins - the globally installed version or local.

0 comments voice your opinion now!
easybib extend composer slide berlinphp global question

Link: http://drafts.easybib.com/post/63085455706/extending-composer

Russell Walker:
Handling Global Data in PHP Web Applications
September 16, 2013 @ 12:31:07

Russell Walker has a post on his site sharing some suggestions about effectively dealing with global data in your PHP applications.

Almost every web application needs to handle global data. There are certain things that just have to be available throughout the entire code base, such as database connections, configuration settings, and error handling routines. As a PHP developer, you may have heard the mantra 'globals are evil', but this naturally begs the question 'what should I use instead of global variables?'

He includes four different options (five including the actual use of global variables):

  • Static classes
  • Singleton
  • Registry
  • Dependency injection

For each of the options he includes summaries of both the advantages and disadvantages as well as some sample code showing their use. Ultimately, he points out that it's up to the developer of the application which option fits best.

0 comments voice your opinion now!
global variable data opinion options registry singleton dependencyinjection static

Link: http://russellscottwalker.blogspot.co.uk/2013_09_07_archive.html

DeveloperDrive.com:
5 PHP Security Measures
July 05, 2012 @ 12:02:53

On the DeveloperDrive.com site today there's a new post with five easy steps you can take to help increase the security of your PHP-based applications.

For many years, PHP has been a stable, inexpensive platform on which to operate web-based applications. Like most web-based platforms, PHP is vulnerable to external attacks. Developers, database architects and system administrators should take precautions before deploying PHP applications to a live server. Most of these techniques can be accomplished with a few lines of code or a slight adjustment to the application settings.

The five tips they list range from general "best practice" kinds of things to a bit more specific:

  • Manage Setup Scripts
  • Include Files (using ".php" not ".inc")
  • MD5 vs. SHA
  • Automatic Global Variables (no longer an issue in recent releases, 5.4.x)
  • Initialize Variables and Values
0 comments voice your opinion now!
security tips include setup md5 sha global variables


Kevin Schroeder's Blog:
A little more advanced ZF2 EventManager usage
April 24, 2012 @ 08:54:55

Kevin Schroeder has a new post to his his blog with a bit more advanced example of using the Zend Framework 2 EventManager to make global event triggers.

If you look at my previous post on the ZF2 EventManager class you might be tempted to think that you are limited only to listening to events for local instances of the event manager. But no, my friend, you would be wrong. The event manager actually provides access to a sort of global event manager. But it's more than that. This global event manager allows you to listen in on events for various targets.

He includes an example of how to use the EventManager in a specific namespace that's triggered based on a custom event. He attaches a custom class, "cls2", to a listener on his "ns1/cls1" class.

0 comments voice your opinion now!
zendframework2 eventmanager example tutorial global


Charles Sprayberry's Blog:
DI and global state
January 31, 2012 @ 09:24:47

In response to some of the comments made on his previous post about why you should use dependency injection in your applications, Charles Sprayberry is back with some more concrete examples showing how it all works with some code to back it up.

To help better explain each of the three aspects of DI I discussed in the previous article I'll be going over each more thoroughly and with those code examples requested. I'll be going through each point one at a time as the explanations will likely be of some length compared to the original post.

He starts with the "villain" of the story - the Singleton design pattern, a difficult to test method that lulls you into thinking you're not in the global scope. He talks about the problem of using this approach and how the Factory design pattern can be used to create an alternative. He changes up the example to create a "DbTableFactory" class that can be used to create the objects needed - in this case a "UserTable" object with the connection injected into it at construct time.

0 comments voice your opinion now!
dependency injection di factory singleton global designpattern


PHP and Me Blog:
How to Type Less $this in PHPUnit
March 10, 2011 @ 13:25:51

In a recent post to the "PHP and Me" blog they look at how to type less $this in your PHPUnit tests using some handy tricks and a bit of custom code.

Lately I've been writing a few tests (using PHPUnit), and when you do there's one thing you end up doing a lot, which is typing $this-> whenever you need to do pretty much anything. It's not that bad (and PHP can be quite verbose itself) but it can become a bit of a bore I guess, especially after a while. [...] Those were valid points [about the global testing functions added to PHPUnit], and for a while that feature was even temporarily removed. So.. now what? Back to typing all those $this-> over & over again? Maybe not.

The post shows how to use the included functions to remove the "$this" in something like "$this->assertTrue()" or, to reduce things even more and not pollute the global namespace, a different approach by extending Assert. A few code examples are included as well as the class that extends the normal Assert functionality PHPUnit provides. It allows for the more flexible short-hand function calls to automatically be mapped back to their "more correct" versions.

0 comments voice your opinion now!
phpunit global method assert namespace


Court Ewing's Blog:
A Simple Alternative to Global Registry Dependency
December 09, 2010 @ 15:19:22

Court Ewing has written up a post looking at an alternative to a commonly used bad design pattern - the global registry dependency - a method that uses a singleton to control access to a class-wide instance of an object.

This gives you flexibility when configuring and setting your adapter, and it allows you to instantiate a new service without having to explicitly set commonly used dependencies, but you are ultimately just replacing one hardcoded object call with another. This means you are still limited in your ability to unit test the class properly, and you will have a difficult time debugging if you ever need to find out exactly when and where your database adapter was configured.

In his simple solution uses static methods to assign the database adapter when the bootstrap process is started instead of when the object is created. This adapter is assigned to an abstract class, so it's created even outside the class instantiations. There's one caveat to doing things this way, though - depending on the needs, you might have to have more than one abstract class and things could get tricky.

0 comments voice your opinion now!
alternative global registry dependency example


Chris Renner's Blog:
Gerrymandered Code Extending Zend_Registry to globalize session vars
January 22, 2010 @ 10:29:50

Chris Renner has put together a new post showing how to use the Zend_Registry component of the Zend Framework to make your session variables easier to get to globally from other parts of your application (and standardize their access).

I've been using $_SESSION like this for a couple of years, and I've known the whole time it was a band-aid approach to solve the problem. Such an approach is not an ideal "design pattern." Though it passes my baseline rule - it works - there are downsides. [...] I refactoring my main app with Zend_Registry in place of my rat's nest of $_SESSION['config']['foo'] and such...which is mostly just things like email addresses for the system admin (me) and other global variables that may come in handy in any script or method.

He talks about how storing values in the session (especially configuration settings) is a bit of "Gerrymandered code" and that the Zend_Registry features allow you to completely replace the need for working directly with $_SESSION. To replace his current functionality, though, he still needed to work with the session values. The result? A wrapper class that has methods for getting and setting to make things a bit more clean.

0 comments voice your opinion now!
zendregistry zendframework global tutorial session


Ant Phillips' Blog:
Singletons, BIRT, Theads and PHP
February 18, 2009 @ 12:55:47

In doing some work with Zero (PHP in Java) and the Eclipse Business Intelligence and Reporting Tools project, Ant Phillips had some troubles with multithreaded PHP processes and wanting them all to use the same BIRT instance insted of spawning their own.

The problem is that BIRT needs to be started once, and only once, in any given process. Once it has been started up, then it is plain sailing to load reports and render them to HTML. The BIRT runtime should be kept around until the process shuts down.

Two problems came up with this approach - if each PHP process makes its own BIRT process any settings/current data will be wiped out and the BIRT instance would go away whenever the PHP script finishes. He found something that solves both of these problems - the Zero Global Context. Its a "storage area" that can contain just about anything. He used it to store the BIRT runtime until its told to finish and die off.

1 comment voice your opinion now!
birt java zero multithread singleton process global context



Community Events





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


api wordpress introduction podcast framework laravel configure bugfix threedevsandamaybe release code series community project application developer language interview list library

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