A new site coming for PHP – a Preview

If you're a PHP Developer, you are familiar with the PHP web site, www.php.net.  This site has looked the same, for I don't know how long, but for at least, six or seven years, if not longer.  The old pastel purple and gray colors were instantly recognized when you went to the web site.

The old PHP site with the PHP 5.39 version annoucement

 

A side note, notice in the image above that PHP 5.3.9 has been released.  This is just a subtle way for me to announce a new release of PHP.

Back to talking about the web site, I have visited the old site a multitude of times, and it's usually my first click when I want to do a quick check for the correct syntax.  The site was OK, but quite frankly, I never cared for it much, and found myself always looking for another site to round out my knowledge of a particular code snippet.

The reason why I didn't like it was I always thought the examples weren't good, and the explanations were worse.  I wanted to see the syntax used in a code snippet, and a simple use, and explanation of the code in question.  Somehow you always ended up paging down the page, and not finding what you were looking for,   It was frustrating.  I also didn't end up reading the comments on the page, because I was in a hurry, and it was just easier to go to another web site, and find a better tutorial.  A lot of my articles on PHP stem from my frustration with the PHP site, and the fact that I needed to go some where else to find what I needed.

Well, this may be changing.  Apparently, I'm not the only one who didn't like the site.  The PHP Group has decided to gradually retire the old site, and is in the process of building a new site, more modern looking, and I, for one, am highly optimistic that this will be a one-stop site for my PHP questions.

The new sites main page

 

You can view a preview of the new site as it is coming together here: http://prototype.php.net/

The really good news, is that The PHP Group is asking for contributions to their documentation, and are not just going to paste the old documentation into the new site.  I have viewed some of the pages in their new documentation, and it seems improved.

A comment on the new design, I think it is a much cleaner looking, an easier-to-read site. At first, I thought the font was too small, but you can re-size the site with your ctrl-mouse wheel to your preferred size font.  You could do that with the old site too.

The font and the white background, not surrounded by gray sidebars, like the old site, is much easier to read.  It makes the site more wide open and not as cluttered.  A big improvement over the old site.  The gray sidebars of the old site were a downer to me, and made me want to move on to another site to get to a brighter and cleaner environment.  The gray of the old site was like a rainy day, gray, and gloomy, and the content was like baby food, bland.  Good reasons to upgrade the site.

Showing the Documentation sub-menu

 

On the new site, if you click on the documentation, community, or help top menu, for example, the site mimics the CodeIgniter documentation layout in using a table of contents as the intro page to that section.  This is a nice touch, and makes you want to look around more than if the option were stuck in the sidebar, like in the old site.  I found myself clicking various topics that provoked my interest, a big plus for the new site.

For a while it looks like you may have to visit both the old and new to get your information, or go to one of those "other" sites.  A lot of the pages on the old site are not available from time to time.  While I was writing this article both sites showed up with white space instead of the documentation.  If you would like to speed the new site along The PHP Group is looking for contributors.

Posted in Web Sites | Leave a comment

NetBeans 7.1 Review

One of outcomes of switching jobs is you lose some of your favorite tools.  For me that was Zend Studio.  Having done PHP development full time for many years, Zend Studio had become my IDE of choice.

Since Zend Studio costs money, as a newbie to my new company, I didn't see a lot of Zend Studio's installed.  In fact, I saw few IDE's.  Most of the edits were done on a Linux server running Vim. This seemed a little archaic to me.  I wanted to set up my beloved work environment, back to open-source.

Naturally, I downloaded Eclipse PDT based on the Helios release, on which Zend Studio is built.  I had used Eclipse before Zend Studio, and so this was pretty close to home.  All the menus and functionality, except for some of the Zend Studio features, are the same.

In the process of configuring Eclipse, I, of course, started messing with preferences.  Anyone who has used Eclipse understands what a nightmare the Eclipse preferences are.  It takes you quite a bit of time to initially configure preferences.  So you don't have to reconfigure then again, you export your preferences and import them to the new Eclipse environments.

I did an import of my Zend Studio preferences and then started changing some setting, and I had a hiccup.  The hiccup was Eclipse balked at some setting I set, and blew away my entire workspace.  I'm guessing Zend Studio preferences have problems with importing to Eclipse.  I had to reload everything including re-configuring my preferences.  What a nightmare.

When things like this happen, I get pissed, and go looking for new tools.  After a preliminary search showed that Netbeans had good reviews, I decided to give it a try.  I had tried Netbeans before, and found it wanting for PHP development, but that was four years ago.  It deserved another look.

NetBeans Initial Start Up Screen

 

Netbeans is a Java application and requires Java to run, which is probably already loaded on your computer.  The Netbeans license is owned by Oracle from its acquisition of Sun, but it is a free and open source IDE.

Since PHP is now an object-oriented language, like Java, NetBeans has incorporated PHP into its editor.  You have a choice to install NetBeans with just the PHP bundle, which is what I did, since I do not do a lot of Java work.

The Netbeans 7.1 download and install was seamless. The installer downloads 46.6 Mb, which grows to 152.5 Mb on install.  By the way, my Eclipse Helios folder checks in at 390 Mb. The installation took about 5 minutes and NetBeans came up quickly and easily.

NetBeans with various Windows open

 

If you do a feature by feature analysis of Eclipse and Netbeans, you'll find that both IDE's pretty much have the same features and functionality.  You'll find several good articles on the web about this, so I won't go into individual features here.

NetBeans main editor window with other windows closed

 

If your doing Java development, Netbeans should be your IDE of choice, since it was built with Java development in mind.  What surprised me was how far Netbeans has come as a PHP development environment.  If your a PHP Developer, NetBeans has integrated support for Git, Debugging, PHPUnit testing, PHPDoc, Smarty templates, Symfony Framework, and the Zend framework. Need I say more.

NetBeans PHP preference screen

 

If both IDE's pretty much have the same functionality, what is the difference between the two?  Well, it comes down to the feel of the IDE as your using them.

I thought about good analogies and similes for the two editors.   Here's my take.  Eclipse is like an old car that you keep fixing up, it's serviceable and runs good, but every once in a while, you get irritated, because something doesn't work right.  Netbeans seems like a new BMW sports car.  If Eclipse is a house built with a series of additions, Netbeans is a house built from the ground up by an architect.  Eclipse feels bloated.  Netbeans feels integrated, not like your bringing up a separate application every time you go to a new area of the IDE.

One major weakness in Eclipse is setting preferences on how you want the editor to work.  Each plugin added to Eclipse has its own preferences, every section of Eclipse has it own preferences.  What that means is setting preferences is a nightmare.  Not only that, if you set a preference in one area, it might not be set in another, and may collide with another preference, sometime throwing errors, or shutting down the editor.  I've had all of this happen.

In contrast, NetBeans preferences are a pleasure.  Colors and fonts are configured in one tab, PHP in another tab.  You can set all colors and fonts for all languages at once, not like Eclipse.

NetBeans Fonts and Colors Preference Screen

 

In all fairness to Eclipse, I'm comparing this to Eclipse Helios PDT.  I downloaded the Eclipse Indigo 64bit and added the PDT plugin, and I find this version quicker,  and much more stable.  I would recommend Eclipse PDT users uninstall Helios, download Indigo, and add PDT.  I think you'll like it  better, if you stay with Eclipse.

In conclusion, because of problems I've had configuring colors with Eclipse, even using the Eclipse Color Theme Plugin I wrote about in another post, I find myself using NetBeans to write my code.

I highly recommend you download and try NetBeans.  You can have both IDE's running at the same time without conflicts.  If you don't like NetBeans, you can stay with Eclipse, but in the process of using both, I think you'll find yourself gradually moving to NetBeans as your IDE of choice.

The NetBeans Icon

Posted in Development Tools, Software Reviews | 13 Comments

The Power of the Internet

Wow, I'm impressed. Yesterday, the Internet held its first protest. A passive resistance protest in the Gandhi tradition. There were no swear words, no violence, no harmful attacks, well maybe, if you count denial of service for overwhelming email submissions to Congress.  The Library of Congress reported a denial of service attack by people opposed to the legislation.

It was an Internet blackout.  Not all sites participated, but the fact that major sites, like Google, Reddit, Craigslist, and Wikipedia coordinated on one day to pull this blackout off, and make the public aware of the SOPA and PIPA legislation was a first, and amazing, considering the independent nature of web site owners. One estimate stated over 10,000 web sites participated in the protest. This is not confirmed, but given the Internet has over 100 Million active sites, the number does not seem that far off.

It is estimated that over 300,000 people sent emails, or called, their Congressman protesting SOPA and PIPA in the last 24 hour period, and over 4.5 Million people signed a Google petition protesting the Bills according to the protest organizers.

What is the aftermath of this one day shut-down-your-site protest, and send emails to Congress?

The Seatle Times reports that Florida Sen Marco Rubio, a bill sponsor, went on Facebook to renounce PIPA, and Texas Senator John Coryn used Facebook to urge colleagues to slow down and reconsider the Bills. South Carolina Senator and Tea Party member, Jim DiMint, used Twitter to announce his opposition.

Congressman are rapidly distancing themselves from the Bills as fast as they can. According to Ars Technica count and the Atlantic Wire 18 Senators, mostly Republican, have backed away from the PIPA and SOPA bills in the last 24 hours. Seven of them co-sponsored the Bill. The Seatle Times reports over 20 House members have reversed their positions. On Tuesday this group supported the Bill, on Wednesday they said that the SOPA and PIPA legislation was flawed and unsupportable.

Congress for the first time realized that the Internet is not just a bunch of web sites to be regulated like a bunch of unruly grade school kids, but that the Internet is a political force, and has considerable more power than the media and movie industry, a supporter of SOPA and PIPA. The end result was that Congress suddenly realized that the Internet can stand up and defend itself.

The Motion Picture industries, a sponsor of SOPA and PIPA, called the blackout "a gimmick" and "business interests are resorting to stunts to punish their users or turn them into corporate pawns."

Hollywood has a powerful lobby in Washington. They just found out that they have a very powerful opponent that they didn't know was there. Hollywood and Congress learned today that the Internet community has a say. Anyone who can get millions of people to take action is a political force that Congress will have to consider in the future.

The Internet and technical community have established that they have a say in the politics of our country. That was not quite as evident before yesterday. Let's hope Congress listens in the future, and that the big players in the Internet community realize, and take advantage, of their suddenly acquired power to push for legislation that helps, not hinders, the development of the Internet worldwide.

Posted in Uncategorized | Leave a comment

Say No to SOPA and PIPA

Let's shut the Internet down, let's kill the jobs it creates, that way Robert Murdoch can sell more papers.  What am I talking about. Well, it could happen with this new SOPA and PIPA legislation that has been proposed in Congress.  This legislation is wrong, and should be stopped.

Let me give you some examples of the power governments have over the Internet that they are just beginning to realize.  I'm a poker player, and yes, I use to play on-line. Admittedly, I don't consider myself that good a poker player, but I still enjoyed the online game.  Note the past tense there.  Back in 2006, on the last day before Congress adjourned, Congress passed the Unlawful Internet Gambling Enforcement Act (UIGEA).  The Bill was attached to a bill that had been passed, the SAFE Port Act(HR4954).  UIGEA was added in conference, and the reading of the bill was waived, in order for Congress to adjourn more quickly.  How the two relate, I don't know.  The bill does not ban online poker, it prohibits exchanging funds related to Internet gambling by banks.  Of course, the bill was so hastily written that Internet gambling is not defined.

The Justice Department decided to enforce this bill in April 2011, on a day known as "Black Friday" in the poker world.  They accused, not the banks, but three prominent poker sites, with bank fraud and illegal gambling.  By the way, no where does it say poker is gambling, and it is called a game of skill by poker aficionados.  The Justice Department effectively turned off the poker sites for US players only. And they've been shut down to US players ever since.

Let's take a look at government Internet censorship.  China is the most stringent Internet censor.  It does more than block sites like other countries.  It also bans a list of key words. If a site contains a banned word anywhere on the site, the site is banned.  China monitors all incoming searches against a list of keywords and sites.  China also crippled VPN's (Virtual Private Networks), the mobile Internet, and phone calls.  Since 2010 the word "freedom" has been banned.  In March 2011, Google complained that the Chinese government was censoring its Gmail service, and making it look like a technical problem at Google.  As a result, Google closed its China offices, and moved to Hong Kong.  Other countries, especially in the Middle East, ban certain type of sites in their countries.

From these past events, it has become increasingly clear to Congress that they can control the Internet.  That's power, and once power is realized, you have created a political football for special interest groups to push laws through that benefit their interests.

What do SOPA and PIPA mean to the use of the Internet?  SOPA and PIPA are two bills currently in Congress.  SOPA stands for "Stop Online Piracy Act",Bill HR112-3261 IH, and PIPA is "Protect IP (Intellectual Property) Act," Bill S112-968 RS.  We're talking copyrighted material: software, pictures, and written articles.  The bills are attempting to stop foreign sites from stealing copyright material from US sites and the Internet.  Sounds like a good idea, but the problem is in the implementation, as in the UIGEA Poker bill.

SOPA pushes enforcement on web site owners.  The way the SOPA bill is set up every site Google, or Wikipedia, with links would need to be monitor those links to make sure no copyrighted material was on the linked to site, an impossible task.  The Bill calls for the site who is in violation, to be subject to seizure, and action can be brought against the owner.  The web site owners must police their site to make sure no copyright infringement takes place.

Anyone who believes that a site is using their copyrighted material, can shut down that site, and you would have to go to court to reopen the site.  A lot of small site owners would not be able to afford lawyer and court costs.  In addition, big sites like Google would be shut down as their is no way the can police their links to the entire Internet.  If one person filed to shut down the site, it would be shut down.  Can you imagine the Internet without Google, or Yahoo, or Wikipedia.

You can help.  As Wikipedia suggests on their site today. You can help by writing your congressman and letting them know that SOPA and PIPA are not good bills for the Internet.  They will kill creativity, jobs, and a lot of Internet sites.  Here's a page that will help you find your congressman .  Send them an email.  Doesn't have to be a long message.  Just say you don't support SOPA or PIPA.  If enough people do this, they'll get the message.

Posted in Uncategorized | Leave a comment

PHP array_push, and other array manipulators

Every once and a while I like to take a closer look at a particular function that I use quite frequently. This let's me make sure I'm using that particular function to the best possible effect. I find it also shifts the center of attention from a task to how the function operates. A different look so to speak. Today, I want to cover the PHP array manipulator family functions that include: array_push, array_pop, array_shift and array_unshift.

All the examples below are visualized with my free, open-source, variable checker that you are welcome to download from my newchk site at www.newchk.com Documentation on how to use it is on the site.

ARRAY_PUSH

Array_push($new_array, $var1, $var2, ...) pushes one or more array elements on to the end of an array, in this case, we'll use $new_array as our array. Seems simple enough. I want to create a new array, and add some variables to it. Let's take a look.

Let's set up our new array.

$new_array = array();
$var1 = "buick";
$var2 = "ford";
$var3 = "toyota";
array_push($new_array, $var1, $var2, $var3);


Let's take a look at $new_array;

If $new_array already exists with elements in it, then new variables are appended to the end of the already existing array. Let's show that.

$var_food1 = "cheese";
$var_food2 = "meat";
$var_food3 = "potatoes";
array_push($new_array, $var_food1, $var_food2, $var_food3);


Here's what the $new_array looks like now.

Some things to note about the array_push() function. It is a function, so there is no equal sign used with array_push. The order the variables are pushed on to the end of the array are in the order their listed in array_push. We can also use associative keys with array_push(), like so.

$var_ball1 = "football";
$var_ball2 = "the rock";
$var_ball3 = "hardball";
$ball_array = array("ball_football" => $var_ball1, "ball_basketball" =>$var_ball2, "ball_baseball" =>$var_ball3);
array_push($new_array, $ball_array );


Here's what the $new_array looks like now.

We've done a little more here than just assign associative keys to the array. We've jumped to what is called a multi-dimensional array. We now have an array within an array. If you look at the code above you see when working with multi-dimensional arrays, you build the inner array first, in this case the $ball_array, and then do an array_push using $ball_array as the variable in the array_push.

What got me to write this article was I was trying to do an array_push in a foreach loop using a multi-dimensional array. This is not well documented on the Internet. I had to look for awhile to find the proper syntax. When that happens I tend to write an article about it. The trick is to make a separate array variable before doing the array_push, and then add that array as a variable to the array_push().

Where do you most often use the array_push() function? Most of the time it's with a foreach loop, where your repetitively looping through an array, and creating a new subset of the array with array_push. Let's see.

$for_array = array();
$i = 1;
foreach( $new_array as $row)
{
	if($i < 7 )
	{
		array_push($for_array, $row );
	}
	$i ++;
}

Here, with a foreach loop, we've removed the second array, and are back to a one dimensional array, called $for_array.

ARRAY_POP

Array_pop($array) pops an element off the end of an array. Let's do it


$spuds = "";
$spuds = array_pop($for_array);


Our $for_array now is minus the last element in the previous array. That element is now in a separate $variable called $spuds. Array_pop() removes the last element in the array, which you can then put into a separate variable.

ARRAY_SHIFT

What if we wanted to remove the first element in the array, instead of the last, like we do with array_pop(). We'll we use array_shift to do this, like so.


$gm = "";
$gm = array_shift($for_array);


The $for_array we started with is getting shorter as the first variable in the array is removed, and put, in this case, in the variable $gm.

ARRAY_UNSHIFT

Finally, since array_push added new variables to the end of the array, you probably have guessed that there is a function that adds variable to the front of the array, and you'd be right. I present to you, array_unshift(). Array_unshift() puts the new variable as the first element in your array. Let's do it.


$gm2 = "cadillac";
array_unshift($for_array, $gm2);


Our array now looks like this.

We've replaced the "buick" we've taken off the top of the array with array_shift, and upgraded to a "cadillac" with array_unshift. Nice trade-up.

If your working with multi-dimensional arrays, the key is to treat the nested arrays as a single array variable, and then use the four functions we've covered: array_push, array_pop, array_shift and array_unshift with that single array variable.

Posted in Sorting Arrays | Leave a comment