If Statement Variable Scope In PHP

Apr 16

If Statement Variable Scope In PHP

Variable scope is the context within your code in which a variable is defined and able to accessed. If you try to access a variable that is out of scope, the variable will be undefined and you will not get the results you are expecting.

In PHP, variables all exist withing the same when your code is inline or included in an include or require statement. The exception to this rule is that classes and functions have their own variable scope. If statements, however, do not have their own variable scope.

Read More

WordPress register_activation_hook not firing

Mar 01

WordPress register_activation_hook not firing

The register_activation_hook() in WordPress looks for the “wp-content/plugins” directory in the plug-in file’s canonical pathname. So, if your files physically live somewhere other than in your WordPress tree, WordPress (PHP) calculates inappropriate paths.

The Solution: Move all your plug-in files into your WordPress tree and the activation hook should start firing.

Read More

Sort Text Column Numerically in MySQL

Jan 23

Sort Text Column Numerically in MySQL

Normally when you want to sort numerically on a column in your database you’d make the column some sort of numeric type such as an int. Sometimes, however, you are stuck with someone else’s schema and they have decided to store numbers in a text type column and you need to sort your results numerically because an alphabetic sort on a number does not produce the results you want. There is a quick trick to that makes this easy.

Read More

John 3:16 In PHP and Ruby

Dec 30

John 3:16 in PHP

$son = $god->loved($the_world);
foreach($whosoever as $person) {
  if($person->believe($son)) {
    $son->everlasting_life($person);
  }
}

John 3:16 in Ruby

son = god.loved(the_world)
whosoever.each do |person|
  son.everlasting_life!(person) if person.believe?(son)
end

Read More

Quickly Folding Functions In Vim

Dec 20

Quickly Folding Functions In Vim

The is really a Vim tip on how to fold any code block including functions. It’s really helpful if you want to collapse a function or any other type of code block. Best of all, it is quick and easy to do.

Navigate your cursor somewhere inside of the code block you want to fold. You do not have to have your cursor on the opening brace, anywhere in the block is fine. Make sure you are in command/normal mode and type:

zfa}

To save your folds between vim sessions you need to issue the command :mkview otherwise when you close vim your folds will be lost (your folds, not your code). To make life easier on you, you can have your folds automatically saved for you by adding this to your .vimrc file

au BufWinLeave * mkview
au BufWinEnter * silent loadview

Read More

Quote A Word In Vim

Dec 19

Quote A Word In Vim

Here is a quick, but awesome little vim tip. To put quotes around a word, put your cursor anywhere on a word and then type:

ysiw'

or if you want double quotes

ysiw"

Read More

PHP Documentation Help In Vim

Sep 29

PHP Documentation Help In Vim

How To Open PHP Documentation From Vim

Supposing you are whipping up some PHP code in Vim and want to quickly check the PHP documentation for the function you just typed. I wrote a quick little script to do just that. It uses the open command is OSX to launch your default web browser to the page in the online PHP documentation for the function name under your cursor. All you have to do is press shift+K

Read More