Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×
PHP

Journal Journal: null == 0...

Looking at the following code:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif ($foo == 0) {
  echo "Foo is 0";
}

If $foo is not defined (as in the case of, say, an unposted $_POST variable), $foo == 0 evaluates as true.

All null values equal 0 apparently, forcing any specific zero-check to look as follows:

if ($foo == 1) {
  echo "Foo is 1";
}
elseif (($foo == 0) && (is_numeric($foo))) {
  echo "Foo is 0";
}

Sometimes I hate this language.

PHP

Journal Journal: Ummm.... why would you do that?

count (PHP 3, PHP 4 , PHP 5)
count -- Count elements in a variable
Description
int count ( mixed var [, int mode])

Returns the number of elements in var, which is typically an array (since anything else will have one element).

If var is not an array, 1 will be returned (exception: count(NULL) equals 0).

Except, for some reason, count($var) where $var == NULL returns 1.

WTF?

User Journal

Journal Journal: Do not do this. 1

This is the kind of programming that gives Perl programmers the reputation of being sloppy and their code unmaintainable (a snippet of code from a major project at my former job):

foreach $data ( sort keys %data ) {
   push @data, $data{$data};
}
PHP

Journal Journal: Explain this to me. Win prizes.

In going over some code that I need to put up, I found the following function (names have been changed to protect the ignorant):

function my_uniq_array($myarray){
  $temparray = array_unique($myarray);
  $i=0;
  foreach ($temparray as $value) {
    $new_array[$i] = $value;
    $i++;
  }
  return $newarray;
}

Can someone explain to me why it would be necessary to do such a thing?
User Journal

Journal Journal: Perl Win32::MsgBox quick ref.

Win32::MsgBox(MESSAGE [, FLAGS [, TITLE]])

[EXT] Create a dialogbox containing MESSAGE. FLAGS specifies the
required icon and buttons according to the following table:
        0 = OK
        1 = OK and Cancel
        2 = Abort, Retry, and Ignore
        3 = Yes, No and Cancel
        4 = Yes and No
        5 = Retry and Cancel

        MB_ICONSTOP          "X" in a red circle
        MB_ICONQUESTION      question mark in a bubble
        MB_ICONEXCLAMATION   exclamation mark in a yellow triangle
        MB_ICONINFORMATION   "i" in a bubble

TITLE specifies an optional window title. The default is ``Perl''.
The function returns the menu id of the selected push button:

        0  Error
        1  OK
        2  Cancel
        3  Abort
        4  Retry
        5  Ignore
        6  Yes
        7  No
User Journal

Journal Journal: Win2k: Internet Connection Wiz: Connection Name problem

From a usenet post to alt.os.windows2000 by Gerry Kroll:

Error:

"Connection to ....." is not a valid name. The entry name must contain at least one character that is not a space and cannot begin with a period. Choose a different name

Solution:

Your problem is a corrupt RASPHONE.PBK file. It has a false end-of-file character in it. Essentially, the EOF character defines a file size that doesn't match what's recorded in the folder's directory.

Since you're going to re-create the entries anyway, simply search for all occurrences of RASPHONE.PBK and delete them.

User Journal

Journal Journal: Python: Strip Leading Zeroes

An algorithm to strip leading zeroes off of a string when you're restricted from using regexes (say, on a Windows CE machine running Python 1.2).

ii = 0
while (string[ii] == '0'):
     ii = ii + 1
string = string[ii]

Slashdot Top Deals

Those who can, do; those who can't, write. Those who can't write work for the Bell Labs Record.

Working...