Search Our Site

Our Newsletter

Our Ramblings

A look at some useful PHP functions. isset() vs empty() vs is_null()

Were currently developing a new system in collaboration with our partners at 802 Works – Redefining Wireless. As a part of that, were designing a new system for administering Wireless systems and maximising the marketing leverage that can be gained from them. That job involves having to write quite a lot of PHP pages and scripts. We thought we’d share a short tip on PHP variable declaration.

We’re going to look at the different ways that variables can be empty in this post. PHP has many different operators which can be used to test a variable. Three useful operators used for this are isset(), empty() and is_null(). Each of these operators return a boolean value (either true or false).

Lets take a look at these operators in a little more detail:

isset()

From the bible of PHP, the PHP manual, isset’s job is to “determine if a variable is set and is not NULL”. In other words, it returns true only when the variable is not null.

empty()

Again from the PHP manual, empty’s job is to “determine whether a variable is empty”. In other words, it will return true if the variable is an empty string, false, array(), NULL, “0?, 0, and an unset variable.

is_null()

Finally, from the PHP manual, is_null’s jobis to “find whether a variable is NULL”. In other words, it returns true only when the variable is null.

You may now be thinking that is_null() is opposite of isset() and , broadly speaking you’d be correct however there is one difference and that is that isset() can be applied to unknown variables, but is_null() only to declared variables.

The table below is an easy reference for what these functions will return for different values.

 

Value of variable ($var) isset($var) empty($var) is_null($var)
“” (an empty string) bool(true) bool(true)  bool(false)
” ” (space) bool(true)  bool(false)  bool(false)
FALSE bool(true) bool(true)  bool(false)
TRUE bool(true)  bool(false)  bool(false)
array() (an empty array) bool(true) bool(true)  bool(false)
NULL  bool(false) bool(true) bool(true)
“0” (0 as a string) bool(true) bool(true)  bool(false)
0 (0 as an integer) bool(true) bool(true)  bool(false)
0.0 (0 as a float) bool(true) bool(true)  bool(false)
var $var; (a variable declared, but without a value)  bool(false) bool(true) bool(true)
NULL byte (“\ 0”) bool(true)  bool(false)  bool(false)

 

I have tested the above values in PHP 7.1.9 which was released on September 1, 2017.

The Warning Signs Your Network Needs Replaced

atlanticstormIf you think lightning can’t strike twice, think again. It can strike twice, thrice or even quarce. (Is that really a protologism?) A well known ferry operator on the West Of Scotland has the blown out network equipment to prove it. The coastal ferry terminals of Scotland are long standing facilities. Surprising to some, in the winter in Scotland, the seemingly constant procession of Atlantic storms frequently bring intense atmospheric instability with them as the UK’s TORnado and storm Research Organisation (TORRO for short) can testify. Lightning frequently is a major problem for many businesses in this area and it can have a devastating effect on their sensitive IT infrastructure. As Doug Rask, an IT manager in the area put it, “We would take an occasional lightning strike and the equipment would be fine initially, but after some days or weeks, they’d start falling over, and we’d have to analyse the problem and quickly get things replaced.” Lightning strikes are admittedly a bit of an extreme example, well concede, but they do qualify the problem of the constant environmental stresses and strains that your static sensitive network hardware has to face almost constantly.

When systems begin to show signs of this wear and tear, it can manifest itself in the shape of chronic network niggles such as poor throughput or frequent hangs, crashes and outages. The hardware may simply be coming to the end of its natural life, or perhaps the user enterprise has simply grown beyond the maximum capabilities of the network, says Pete Macsorley, IT manager at Corpach Pumps. Other factors that can cause an agency to consider a network refresh could be the deployment of new applications such as anti virus systems or phased migration and collaborative services. Usually the real world reason for a network overhaul is not just a single warning sign but a combination of multiple elements of the above.

CONSISTENT EQUIPMENT FAILURE

When lightning strikes a building, the earthing systems should and almost always will protect the systems but every now and again a strike of ferocious magnitude can overwhelm these safety systems to the point that damage is caused to the network  and IT equipment. “When we get strikes on our sites, it typically doesn’t kill of our systems there and then. It does however initiate a collapsing system which culminates in the eventual hard failure of equipment. This can take 3-6 months,” said Mark Forrest, IT engineer for a well known salmon farming company.

At some time in the next 6 months, the kit would begin to play up. Users would notice a badly performing network, intermittent hangs and patchy access to servers, forcing Forrest to carry out systematic fault finding and replace the failing kit. “Atmospherics and particularly lightning places a cost burden of 3 to 4 switches per hit” says Marks boss, Joe McGarry.

AGEING HARDWARE

headerAgeing or end-of-life networking gear can compel organisations to replace their systems, especially when the initial warranty expires and/or support organisations place a premium on their support due to the increased likelihood of call out and expensive engineering time. “Sometimes this cost uplift is so great that there is no option left but to replace new for old and enjoy the more relaxed maintenance landscape that ensues,” says Dan McDougall, CTO at a major food manufacturing company.

“Networks are there for one reason, to serve the business. Unless they’re failing too frequently, the main reason we would decide to upgrade the network is the cost of their support,” McDougall says. “Sometimes the kit on your business network is just so old that the cost of the warranty dwarfs the cost of new for old.”

For example, the salmon farming company mentioned previously recently needed to move their regional offices in Oban. It made perfect sense to look at equipping the new premises with a new network and servers because most of the kit at the old office was 5-9 years old and EOL (End Of Life), Forrest says “I was sure I didn’t want to be moving any of my old equipment that had been through the lightning hits more than once. I wanted new for old.”

They had also decided to move some services to the cloud such as their voice network services and had enhanced the resolution with which they remotely monitored the underwater salmon pens. They purchased 2 Cisco UCS servers, three new routers, eight switches and upgraded their WIFI network using Cisco Meraki, Furthermore in addition to moving to hosted voice, they improved the storage of their IP video inputs from the farm cages as well as a new access and building control system which also used the network. This network upgrade brought with it gigabit networking to the desktop and has markedly increased the performance and efficiency of the business unit.

For example, in the past, bandwidth contention had sometimes resulted in the live video from the pens squeezing out the traffic for the very control systems which were used to enable the application of feed to the pens. The upgraded network, using 802.1q VLAN trunking was able to segment the traffic and ensure that the requirements of each business process were safeguarded. Bandwidth contention had become a thing of the past. Finally and perhaps ironically, they also installed a new earthing system and new earthing cable, which should protect the new locations sensitive electronic equipment more effectively from future lightning strikes.

CREATING BANDWIDTH

Sometimes, the introduction of new applications on the network necessitates a network upgrade. For example, VoIP (hosted or owned) or realtime video services can place very specific demands on a network and if it isn’t up to the job, a refresh can prove inevitable,

An increased rollout of virtualisation and thin client technology can also drive cost savings in terms of network user hardware which may be partially offset by the costs of the new network to support it.

CONTINUOUS PHASED APPROACH

tick-tock-google-searchSome agencies adopt what is best described as a continuous phased approach to keeping the network at the cutting edge. This can prove to be a useful mitigation to the sometimes problematic expense of replacing the whole network every few years as well as enabling financial planners to smooth the requirement for capital across many financial years. It’s a cost-effective way of keeping the network stable and up to date.

DB Refrigeration in Ayr, for example, has gradually upgraded most of its 15 wiring-closet switches since 2012 and will replace a few more this year, says IT manager, Connor Piacentini.

This autumn however, it was the core routers turn to be replaced. The IT department upgraded its Gigabit Ethernet Cisco Catalyst 6509 core switch to a 6509-E which could support 10 Gigabit Ethernet. “It was 8 years old, so we knew we had to upgrade it finally,” Piacentini says.

SHARED SERVICES

Consolidation by agencies of the use of their expensive network resources seems to be a popular way to save costs these days. For example in the Public Sector, many regional councils share some of the higher end networked resources making the burden on each organisation smaller. This can however mean that the new network  must be far more capable than any of the incumbents.

Police Scotland, following its recent merger has to build regional backup emergency operations facilities, so if disaster strikes and one goes down, another can take over. The investment requires new network equipment to build the WAN. It is speculated at this time that they are also negotiating with infrastructure providers to build a proprietary fibre ring.

Upgrade Advice

1. Plan for future needs. When deciding how much bandwidth you need and what equipment to buy, don’t assess for your current needs. Spec it out for five years from now. A good rule of thumb is to plan for a 50 percent increase in bandwidth usage and a 30 percent increase in the number of employees.

2. Pair a network upgrade with a larger technology project. It’s often easier to prove return on investment and get a network upgrade funded if it’s tied to a bigger project. When IT administrators propose a private-cloud deployment, for example, they can argue that a network upgrade is critical for good cloud performance.

3. Purchase maintenance contracts only on the most critical equipment, such as main routers and switches. Purchasing contracts on all equipment can be cost-prohibitive. It can be cheaper to purchase one backup wiring closet switch and use that if a switch fails instead of purchasing contracts for each switch.

Which website shopping cart?

We have recently undertaken a study to determine which of the many shopping cart systems we should use on a customers website. After a long process trawling through the myriad of options we finally reached a shortlist of 8 candidates.

These candidates were:

  • Avactis
  • CS Cart
  • Cube Cart
  • Magento
  • OS Commerce
  • Prestashop
  • Virtuemart
  • Zen Cart

Now, with that part done the hard work begins.

The fact of the matter is that all of the choices in the list above are great ones. Any of these shopping carts will, with the right implementation, produce an excellent level of functionality on any website. The trick is to understand your own requirements first and identify which of the options most closely fits your own requirements, not only today but also your anticipation of what they will be in 6 months, 1 year and possibly even more.

So lets look at the pros and cons of each.

You can find the comparison HERE.

 

Making Links to Pages that aren’t in a Site Menu with Joomla

Often, when using Joomla you might want to make a link to a page without having to have it in a navigation menu somewhere. Examples might include:

  • Forms
  • A Google AdWords landing page
  • A special offer in an off-line advert

What you have to undertsand is that in Joomla, a page can not exist unless there is a link in a menu to it somewhere. But, didn’t we just say that we didn’t want it linked on any navigation. Well, here is the trick, the menu that the link is in doesn’t have to show on the site…

Do the following:

  1. Make a category for the pages (or they could all be static pages)
  2. Make a menu to “hold” the links to these pages. For example, make one called hiddenmenu. You can put your items which will not be linked to by a visible site menu in here.
  3. Make a static item called “The Hidden Menu”. It can be blank
  4. Publish the module that outputs the “hiddenmenu”.
  5. Note the link to the “The Hidden Menu” page.
  6. Set the secretmenu module to only show on “The Hidden Menu” page

Now, Any time you need a link to pages/categories that don’t have a link from the main menu, just make the link in the “hiddenmenu”. Then go to that page you noted in 5 above and the link should be there. Just right-click and “copy link location” and you have your URL.