HomePhorge

(PUP-4178) Move defined function to 4.x to correct behavior
c8ce62a4ba06Unpublished

Unpublished Commit ยท Learn More

Repository Importing: This repository is still importing.

Description

(PUP-4178) Move defined function to 4.x to correct behavior

Before this, the 3x defined() function beahaves in a strange way when
giving undef and empty string as input. A user may want to check if a
variable is defined and calls:

defined($not_defined)

and becomes surprised when true is returned even if the variable is not
defined. The user should have asked for:

defined('$not_defined')

This anomaly is caused by the 3.x functions inability to distinquish
between undef and an empty string, and the strange naming of the
Class[main] which is called '' (the empty string) internally, and 'main'
externally.

This commit fixes this problem by adding a 4.x implementation of the
defined() function. This version:

  • does not accept undef input (protects users from the mistake of defined($foo)).
  • the empty string produces false
  • the string 'main' produces true (note that there is always a main

class)

The documentation for the 3x defined function is also updated to reflect
this (to avoid confusion).

This also fixes the ticket PUP-4331 since what it suggest (giving an
error when given undef) is implmented by typing the arguments to the
function.

Event Timeline

Henrik Lindberg <henrik.lindberg@cloudsmith.com> committed rPUc8ce62a4ba06: (PUP-4178) Move defined function to 4.x to correct behavior (authored by Henrik Lindberg <henrik.lindberg@cloudsmith.com>).Apr 21 2015, 5:57 PM