SlideShare a Scribd company logo
1 of 117
Surprise! It's PHP  
by 
Sharon Lee Levy 
[ unabridged PPT slideset ]
Surprise! It's PHP  
I. Introduction 
II. What's in a Name? 
III. The Mysterious 
Comma 
IV. Exploring Truth Values 
V. Additional Thoughts 
VI. Online Resources
Concluding someone … designed 
PHP the way it is today. It has 
history and heritage. 
3 
Common PHP Mistake 
Flickr: by joanmaffeiart 
Mike Wallner 
See http://www.7php.com/php-interview-michael-wallner
Flickr: by derickrethans
... PHP seems to almost read 
your mind … 
5 
Flickr: by joanmaffeiart 
Rasmus Lerdorf 
See "The Early Days of PHP" interview
6 
Flickr: by joanmaffeiart
Artsy Hole 
Flickr: by estherase 
See Internals List: 3/2014
A valid variable name starts 
with a letter or underscore… 
8 
….. 
See Manual: Basics
9 
I ♥ UTF-8 
<?php 
$♥ = "love"; 
echo "I $♥ PHP!"; 
// I love PHP! 
See php_in_webapps.pdf; StackOverflow: unicode-identifiers-function-names…, 
JDN Interview of Andi Gutmans June 2014
10 
<?php 
I ♥ UTF-8 
const START= 0; 
$len = mb_strlen( "♥", '8bit' ); // 3 
echo mb_substr( "♥", START, $len ); // ♥ 
// otherwise: [e2 99 a5]
11 
<?php 
I ♥ UTF-8 
class Test{ const AB♥ = "alphabet"; } 
$rc = new ReflectionClass("Test"); 
$t = array_keys( $rc->getConstants())[0]; 
$substr = substr( $t, -1,1 ); 
if ( $substr === "♥" ) { 
trigger_error(""♥" in "$t"",E_USER_ERROR ); 
} 
// [ PHP5.4 - 5.6 ]
12 
<?php 
I ♥ UTF-8 
class Test{ const AB♥ = "alphabet"; } 
$rc = new ReflectionClass("Test"); 
$t = array_keys( $rc->getConstants())[0]; 
$substr = mb_substr( $t, -1,1 ); // PHP 5.6 
if ( $substr === "♥" ) { 
trigger_error(""♥" in "$t"", E_USER_ERROR); 
} 
// Fatal error: "♥" in "AB ♥" …
That's not a hole in the design. 
Rasmus Lerdorf 
Internals List 3/12/2014 
13
Flickr: by comma?
The Mysterious Comma 
15 
echo_expr_list: 
<?php 
echo $var1, $var2, … 
See Manual: Operator Precedence 
 Left Associative 
 Many Uses 
 Has Least Precedence
The Mysterious Comma 
16 
echo_expr_list: 
<?php 
echo $var1, $var2, … 
See PHP5.2 Changelog, lxr.php.net: echo_expr_list
17 
<?php 
class Test { 
const ALPHA = 1, BETA = 2, GAMMA = 3; 
public $a = "apple", $b = "bread", $c = "candy"; 
// methods … 
} 
See StackOverflow: comma operator vs comma separator
18 
$a = 10, $b = 20, $c = 30; 
See lxr.php.net: zend_language_parser.y
19 
list( $a, $b, $c ) = array( 10, 20, 30 ); 
var_dump( $a, $b, $c ); // 10, 20, 30
20 
Comma Operator 
 C 
 C++ 
 Perl 
 PHP? 
 JavaScript 
See Wikipedia: Comma Operator
JavaScript's Comma 
21 
// JavaScript 
var a = 2; 
var b = 4; 
var c = ( ++a, b * a ); 
// result: 12
not likely to be implemented... 
bogussing. 
Internals List 2/1/2002 
22
23 
<?php 
for ( 
$a = 3, $b = 4; 
$a < $b; 
$a++; 
) { 
$result = $a * $b; 
} 
var_dump( $result ); 
// int( 12 ) 
See doc.ic.ac.uk/lab/cplus/cstyle.html
24 
<?php 
$a = 2; 
$b = 4; 
for ( ; ++$a, $a < $b; ) { 
$res = $a * $b; 
} 
var_dump( $res ); 
// int( 12 ) 
See comma.html
Flickr: by derickrethans
26 
<?php 
echo null < -1 && null == 0; 
// true 
See PHP: a fractal of bad design
27 
JavaScript's Null 
// JavaScript 
alert( null < -1 && null == 0 ); 
// false 
See Ecma-262.pdf; StackOverflow: why-null-0-null-0-but-not-null-0
Flickr: by tajai
See StackOverflow uppercase-booleans-vs-lowercase-in-php and use-true-false-null; 
29 
TRUE, FALSE, and NULL 
keywords should always be 
fully uppercase. 
Coding Standards: CodeIgniter 2.20
… true, false, null … should be 
all lower case, as upper case is 
reserved for constants. 
Coding Standards: FuelPHP 
30
Constants should always be … 
uppercase … This includes …PHP 
constants … TRUE, FALSE and 
NULL… 
Coding Standards: Drupal 
31
… PHP constants true, false, 
and null MUST be in lower case. 
32 
Coding Standard: PSR-2 
See php-FIG: PSR_2 and 8/2014 discussion: http://tinyurl.com/mdasjak
… in PHP, they are not constants; 
they are keywords mapping to 
language constructs. 
Matthew Weir O'Phinney 
Project Lead, Zend Framework, 2012 
33 
See Programming PHP by Rasmus Lerdorf, et al; Manual: define()
To specify a boolean literal, use 
the keywords TRUE or FALSE. 
34 
See Bug report #67228
To specify a boolean literal, use 
the constants TRUE or FALSE. 
35 
See Manual: Booleans
36 
Technically … count more as 
reserved keywords than 
constants… 
Nikita Popov 
See Stackoverflow: NickiC 2/7/2014
…case insensitive, to be 
downwards compatible and 
consistent with other languages… 
Zeev Suraski 
37 
See Internals List: 5/8/98
38 
Flickr: by thebittenword.com
Proof in the Pudding … 
39 
TRUE, FALSE, NULL 
 Usable as Identifiers 
 Ea. Has a Data Type 
See Manual: Reserved Constants, Language: Constants, Zend API: Hacking the Core of PHP; 
PHP Language Spec; 3v4l.org: V3H2n; Internals List: 7/16/2004
40 
PERL Legacy 
Flickr: by ♫ Desmatron ♫
PERL Legacy 
… truth value of expressions 
in PHP is calculated in a 
similar way to perl. 
41 
Zero 
Zero 
C false 
JavaScript false 
Perl false 
PHP false 
Python false 
Ruby true 
LISP true 
Scheme true 
 False: 0 
 True: !0 
 False: "" and "0" 
 True : 1 [<,>,<=,=>,==] 
PHP 3.0b4: lang-const.sgml
42 
PERL Legacy 
 False: 0 
 True: !0 
Perl 
 False: "" and "0" 
 True : 1 [<,>,<=,=>,==] 
See 3v4l.org: TrT4l; PerlMonks; What is true and false …
43 
PERL Legacy 
Zero 
Zero 
C false 
JavaScript false 
Perl false 
PHP false 
Python false 
Ruby true 
LISP true 
Scheme true 
See StackOverflow: why-treat-0-as-true-in-ruby; is-false-0-and-true-1-in-python…
True/False as C Macros 
44 
#define TRUE 261 
#define FALSE 262
True/False as Keywords 
45 
PHP3 Beta5 (2/98) 
PHP_TRUE 1 
PHP_FALSE "" 
See Internals List 2/25/98 and bug report #354
True/False as Keywords 
46 
PHP3 Beta5 (2/98) 
<IN_PHP>"FALSE" { 
phplval->value.strval = empty_string; 
phplval->strlen = 0; 
phplval->type = IS_STRING; 
return PHP_FALSE; 
} 
<IN_PHP>"TRUE" { 
phplval->value.lval = 1; 
phplval->type = IS_LONG; 
return PHP_TRUE; 
} 
See PHP3.0b6: language_scanner.lex, parser.h, language-parser.tab.c, 
configuration-parser.tab.c (and v.3.0, too)
True/False as Keywords 
Made chown(), chgrp() and 
chmod() return TRUE/FALSE 
instead of 0/-1. 
PHP 3.0b5 ChangeLog 
47 
PHP3 Beta5 (2/98) 
See Internals List 2/25/98
48 
PHP3 Constant 
 name: true, false, … 
 name_len 
 value 
value (pval) 
value: [1, ""] 
type: [IS_LONG, IS_STRING] 
See Internals List 5/8/98, 7/1/98 ; PHP3 constants.[ch], 
php.h; PHP3 Manual: Language constructs
Until PHP3rc5 … 
$a = foo; 
// Notice: 'foo' is not a valid constant[ PHP3rc5+ ] 
// Notice: Use of undefined constant [ PHP4.3+ ] 
$a = "foo"; // mandatory: quoted 
49 
See Internals List: 5/24/98; PHP3: language-parser.tab.c, line 2642
50 
Design & Consequences 
if ("5") { 
echo "Would print"; 
} 
if ("5"==TRUE) { 
echo "Would not print"; 
} 
Zeev Suraski 
General List: 7/1/98 
See lang-const.html
51 
PHP4 Reinvention 
zend_constant 
See PHP 4: zend_constants.[ch], zend.h 
value 
value (zval) 
value: [1, 0] 
type: IS_BOOL
52 
PHP4 Reinvention 
<?php 
var_dump( (bool) 1); 
// bool( true ) 
See Andi Gutmans commit 4/71999: zend_constants.c; Extending and Embedding PHP by Sara Golemon, p 
165; Internals List: 6/4/2000
53 
<ST_IN_SCRIPTING>"NULL" { 
ZVAL_NULL(zendlval); 
return T_NULL; 
} 
<ST_IN_SCRIPTING>"FALSE" { 
ZVAL_FALSE(zendlval); 
return T_FALSE; 
} 
<ST_IN_SCRIPTING>"TRUE" { 
ZVAL_TRUE(zendlval); 
return T_TRUE; 
} 
Deja Vu? 
See php-cvs: 7/16/2004, Internals List: 07/16/2004, lxr.php.net: zend_language_scanner.l 
(History: Marcus Boerger 7/16/2004);
Improved Booleans 
54 
PHP5.6: 
Z_LVAL_P(__z) = ((b) != 0); 
Z_LVAL_P(__z) = IS_BOOL; 
PHPNG: 
Z_TYPE_INFO_P(z) = (b) ? IS_TRUE : 
IS_FALSE; 
See PHP5.6 and PHPNG: zend_constants.h, zend_constants.c, zend_API.h; 
PHPNG: zend_types.h; also wiki.php.net: phpng; Internals List 11/10/2013
… I misunderstood the expression 
evaluation of NULL/FALSE of PHP 
for my entire PHP life  
Yasuo Ohgaki 
Internals List 11/10/2013 
See blog.ohgaki.net: php-bool-null ( use Google translate); zend types.h: zval_bool and 
zend_vm_execute.h: isset/empty handler 
55
…please, don't make php 
programmers go berserk :) 
56 
Michal Vitecek 
See bug report: #4805
57 
<?php 
echo ( !1 ); // PHP3: 0 
echo ( !1 ); // PHP4: 
See Internals List: 6/4/2000; PHP3: language_parser.y and operators.c
ZEND_API int boolean_not_function(zval *result, zval *op1) 
{ 
zval op1_copy; 
zendi_convert_to_boolean(op1, op1_copy, result); 
58 
result->type = IS_BOOL; 
result->value.lval = !op1->value.lval; 
return SUCCESS; 
} 
See PHP4: zend_operators.c
59 
… echo nothing at all? 
That's a bit Perlish for 
me! 
John Sutton 
Internals List, 7/1998
60 
Invisible False 
<?php echo false; 
Opcode Return Value Operands 
ECHO false
Invisible False 
ZEND_ECHO_SPEC_CONST_HANDLE 
R 
61 
zend_print_variable() 
zend_print_zval() 
zend_print_zval_ex() 
See lxr.php.net: zend_vm_execute.h
62 
Invisible False 
zend_print_zval_ex(): 
zend_make_printable_zval() 
/* optimize away empty strings */ 
return 0 
write_func() 
See lxr.php.net: zend.c#311; also: How-to-add-new-syntactic-features-to-PHP.html by 
Nikita Popov
false has to be an empty string 
to correctly evaluate to false. 
63 
See Manual: Strings 
Rasmus Lerdorf 
Bug Report #49097
64 
"0" <=> false <=> "0" 
"" => false => "0" 
See StackOverflow: why-doesnt-php-print-true-false
65 
"" <=> false <=> "" 
"0" => false => "" => 0 => "0" 
See StackOverflow: php-get-bool-to-echo-false-when-false
Flickr: by Tracey Stephens
67 
<?php 
for ( $i = 1; ;$i++ ) { 
if ($i > 10) { 
break; 
} 
print $i; // 12345678910 
} 
See PHP-3.0b4: lang-const.sgml, StackOverflow: what-does-for-mean, PHP5.6: zend_language_parser.y
68 
for_expr: 
/* empty */ { 
$$.op_type = IS_CONST; 
Z_TYPE($$.u.constant) = IS_BOOL; 
Z_LVAL($$.u.constant) = 1; 
} 
See PHP-3.0b4: lang-const.sgml, StackOverflow: what-does-for-mean, PHP5.6: zend_language_parser.y
69 
<?php 
$_POST[ "quantity" ] = "0"; 
if ( !empty( $_POST[ "quantity" ] ) ) { 
echo "It's not empty"; // PHP 3 
} else { 
echo "It's empty"; // PHP 4 
} 
See Internals List 5/11/2000, Manual: empty PHP3 and PHP4; bug report #: 2088
70 
empty() considers "0" as 
non-empty, a value that … 
may come from an HTML 
form. 
See Internals List 5/11/2000, Manual: empty PHP3 and PHP4; bug report #: 2088
71 
<?php 
var_dump( "", "0" ); 
// string(0) "", string(1) "" 
var_dump( (bool) "" ); 
// bool(false) 
var_dump( (bool) "0" ); 
// bool(true) 
var_dump( (bool) "0" ); 
// bool(false) 
See Manual: Booleans, bug report # 39904
72 
Boolean "0" 
Perl false 
PHP false 
C true 
Python true 
Ruby true 
JavaScript true/false 
See Manual: Booleans, bug report #39904, perlmonks.org: what is true and false in perl, 
codepag.org: ScNhuOqY, 5zOu4NjN , Internals List: 2/25/98, 5/11/98, PHP3 ChangeLog: 5/11/98
73 
JavaScript's "0" 
// JavaScript 
if ("0") alert(""0" is true"); // true 
if ("0" == false) alert(""0" is false"); // true 
See StackOverflow: why-does-0-a-b-behave-different-than-0-true-a-b
"0" is no longer considered 
false … 
74 
- 
Zeev Suraski 
See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
75 
…we're still thinking whether 
"0" should be considered false 
Andi & Zeev 
See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
"" (string,false) <=> 0 (int, false) <=> "0"(string,true) 
76 
See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
***NOTE*** Changed "0" to 
mean FALSE again 
77 
See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
78 
<?php 
echo empty( "" ); // 1 
echo empty( "0" ); // 1 
echo (int) ( "" == "0" ); // 0 
See 3v4l.org: U0G6L#v430, Manual: empty, Internals List: 8/20/2014
79 
<?php 
$a = "0.0"; 
$b = 0.0; 
var_dump( $a == $b ); // true 
var_dump( empty( $a ) ); // false 
See Bug report #: 60402 and The Manual; pickingUpPerl_5.html; 
PHP4 Manual: migration4.empty.html
80 
<?php 
$items = false; 
echo count( $items ); // 1 
$it = new EmptyIterator; 
var_dump( count( $it ) ); // 1 
See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
81 
Counts all elements in an 
array, or something in an 
object 
PHP5 Manual 
See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
Returns the number of elements 
in var, … typically an array … 
anything else will have one 
element ... 
82 
PHP3 Manual 
See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
83 
switch (Z_TYPE_P(array)) { 
case IS_NULL: 
RETURN_LONG(0); 
break; 
case IS_ARRAY: [snipped] 
case IS_OBJECT: 
/* handler defined? */ 
/* If Countable, call count() method */ 
default: 
RETURN_LONG(1); 
break; 
} 
See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
Flickr: by Steve Mynett
Dec 28, 1999 (Thies Arntzen) new constant SQL_NULL 
PHP4.0b4: (Feb 2000) 
Added new NULL constant (Zeev, Zend Engine) 
85 
About Null 
c.value.value.lval = 0; 
c.value.type = IS_LONG; 
See Thies Arntzen's Commit, PHP4 Changelog; PHP 4: zend_constants.c; bug report: #67562
86 
About NULL 
zend_constant 
value 
value (zval) 
vvaalluuee:: [[ uunnsseett ]] 
ttyyppee:: IISS__NNUULLLL 
null is not a value, was never 
meant to be a value, and won't 
be a value. 
Zeev Suraski 
Internals List 8/17/2003 
See PHP4.0b4 Changelog; PHP 4: zend_constants.c; bug report: #67562
87 
<?php 
echo (int) null; 
// 0 
See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
88 
// Dec. 31, 1999 – introduced IS_UNSET - Zeev Suraski 
convert_to_long_base( zval *op, int base ): 
switch (op->type) { 
case IS_UNSET: 
op->value.lval = 0; 
break; 
See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
89 
// Jan 4, 2000: IS_UNSET => IS_NULL - Andi Gutmans 
convert_to_long_base( zval *op, int base ): 
switch (op->type) { 
case IS_NULL: 
op->value.lval = 0; 
break; 
See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
90 
<?php 
$a = "apple"; 
$a = null; 
echo isset( $a ); // false 
unset( $a ); 
echo isset( $a ); // false 
echo isset( $b ); // false 
See Internals List: 7/3/2014
91 
<?php 
// null detection: 
echo isset( $var ); // false 
echo empty( $var ); // true 
See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
isset( $var ) && $var == NULL // Internals List 
!isset($var) || $var == false // The Manual 
ZVAL_BOOL(&EX_T(opline->result.var).tmp_var, 1); 
92 
<?php 
/* if (opline->extended_value & ZEND_ISEMPTY) */ { 
if (!isset || !i_zend_is_true(*value)) { 
See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
93 
<?php 
// null detection: 
echo is_null( $var ); // true, but… 
echo (null === $var ); // ditto 
See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
94 
# Perl: 
unless( defined( $var ) ) { # unless == if ! 
print "$var is undefined"; 
} 
See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
95 
<?php 
See StackOverflow: Eisberg 
$n = null; 
var_dump( array_key_exists( 'n', 
get_defined_vars() ) ); 
// true
96 
<?php 
See StackOverflow: Eisberg 
$n = null; 
unset( $n ); 
var_dump( array_key_exists( 'n', 
get_defined_vars() ) ); 
// false
97 
<?php 
$count = count( get_defined_vars() ); 
$myvar = null; 
$recount = get_defined_vars(); 
var_dump( array_slice( $recount, $count + 1) ); 
// array(1) { ["myvar"]=> NULL } 
See StackOverflow: Eisberg
98 
<?php 
See Internals List 6/5/2005 
$count = null; 
$count++; 
var_dump( $count ); // int(1) 
$count--; 
var_dump( $count ); // null
99 
// int increment_function 
case IS_BOOL: 
op1->value.lval++; 
op1->type = IS_LONG; 
break; 
case IS_NULL: 
op1->value.lval = 1; 
op1->type.lval = IS_LONG; 
// int decrement_function 
case IS_BOOL: 
op1->value.lval--; 
op1->type = IS_LONG; 
break; 
case IS_NULL: 
op1->value.lval = -1; 
op1->type = IS_LONG; 
Excerpted from Johannes Schlueter's Patch; see also Tjerk Meesters' 
RFC:Normalize increment and decrement operators
100 
// JavaScript: 
var m = null, n = null; 
alert( ++m ); // 1 
alert( --n ); // -1 
var e = true, f = false; 
alert( ++e ); // 2 
alert( --f ); // -1
101 
<?php 
// * Sum byte values from position x in $str 
function sum( $str, $x ) { 
$sum = 0; 
for ( $max = strlen( $str ); 
$x < $max; 
++$x ) { 
$sum += ord( $str[ $x ] ); 
} 
return $sum; 
} 
$str = 'Hello, Dolly'; 
echo sum( $str, strpos( $str, 'F' ) ); // typo: sh/b 'D' 
See Internals List 6/5/2005, Johannes Schlueter's Patch and Tjerk 
Meesters' RFC: Normalize increment and decrement operators
Compare NULL & Any 
102 
 Convert both sides to bool 
 FALSE < TRUE 
See Internals List 11/10/2013; Manual: comparison operators: PHP5.3 and PHP5.5
Compare NULL & Any 
103 
<?php 
echo null < -1; 
echo false < true; 
See Internals List 11/10/2013; Manual: comparison operators: PHP5.3 and PHP5.5
Code Compliance? 
104 
<?php echo null < -1; 
Opcode Return Value Operands 
IS_SMALLER ~0 null, -1
105 
Is_Smaller 
ZEND_IS_SMALLER_SPEC_CONST_CONST_HANDLE 
R 
ZVAL_BOOL(result, 
fast_is_smaller_function: 
compare_function(result, null, -1) 
… 
) 
See PHP5.6: zend_vm_execute.h, zend_operators.h,
PHP4: Compare_Function 
/* op1->type == IS_NULL */ 
zendi_convert_to_boolean(op1, op1_copy, result); 
zendi_convert_to_boolean(op2, op2_copy, result); 
result->type = IS_LONG; 
result->value.lval = NORMALIZE_BOOL( 
op1->value.lval-op2->value.lval 
); 
106 
return SUCCESS; 
See zend_operators.c, PHP4
PHP4: Compare_Function 
/* op1->type == IS_NULL */ 
zendi_convert_to_boolean(op1, op1_copy, result); 
zendi_convert_#define to_NORMALIZE_boolean(op2, op2_BOOL(copy, n) 
result); 
result->type = IS_LONG; 
result->value.lval = NORMALIZE_BOOL( 
op1->value.lval-op2->value.lval 
); 
107 
return SUCCESS; 
 
((n) ? (((n)>0) ? 1 : -1) : 0) 
See zend_operators.c, PHP4
PHP5: Compare_Function 
if (Z_TYPE_P(op1) == IS_NULL) { 
zendi_convert_to_boolean(op2, op2_copy, result); 
ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0); 
return SUCCESS; 
} 
108 
* See lxr.php.net: PHP_5_6/Zend/zend_operators.c#1593
109 
Is_Smaller Result 
ZEND_IS_SMALLER_SPEC_CONST_CONST_HAND 
LER 
ZVAL_BOOL(result, 
fast_is_smaller_function: 
compare_function(result, null, -1) 
return Z_LVAL_P(result) < 0 
) 
See PHP5.6: zend_vm_execute.h, zend_operators.h,
110 
Flickr: by fxalau
111 
<?php 
var_dump( null == false ); 
var_dump( false == 0 ); 
var_dump( null == 0 ); 
// true
Internals of Equality 
112 
<?php null == 0; // True 
Opcode Return Value Operands 
IS_EQUAL ~0 null, 0 
Recommended reading: Anatomy of Equals by A. Ferrara
compare_function(result, null, 0); 
… 
113 
Is_Equal 
ZEND_IS_EQUAL_SPEC_CONST_CONST_HANDLER 
ZVAL_BOOL( result, 
fast_equal_function(): 
) 
See lxr.php.net: PHP_5_6/Zend/zend_vm_execute.h#3475
PHP5: Compare_Function 
if (Z_TYPE_P(op1) == IS_NULL) { 
zendi_convert_to_boolean(op2, op2_copy, result); 
ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0); 
return SUCCESS; 
} 
114 
See lxr.php.net: PHP_5_6/Zend/zend_operators.c#1593; PHP5.2: zend_operators.c
compare_function(result, null, 0); 
return Z_LVAL_P(result) == 0; 
115 
Is_Equal 
ZEND_IS_EQUAL_SPEC_CONST_CONST_HANDLER 
ZVAL_BOOL( result, 
fast_equal_function(): 
) 
See lxr.php.net: PHP_5_6/Zend/zend_vm_execute.h#3475
116
Resources 
 3v4l.org 
 codepad.org 
 lxr.php.net 
 markmail.org: "PHP Internals List" 
 museum.php.net 
 slevy1.wordpress.com

More Related Content

What's hot

Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
mussawir20
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
Olve Maudal
 
Php(report)
Php(report)Php(report)
Php(report)
Yhannah
 

What's hot (20)

Preparing for the next php version
Preparing for the next php versionPreparing for the next php version
Preparing for the next php version
 
Elegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and ExceptionsElegant Ways of Handling PHP Errors and Exceptions
Elegant Ways of Handling PHP Errors and Exceptions
 
PHP - Introduction to PHP Error Handling
PHP -  Introduction to PHP Error HandlingPHP -  Introduction to PHP Error Handling
PHP - Introduction to PHP Error Handling
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
 
Php exceptions
Php exceptionsPhp exceptions
Php exceptions
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
Errors, Exceptions & Logging (PHP Hants Oct '13)
Errors, Exceptions & Logging (PHP Hants Oct '13)Errors, Exceptions & Logging (PHP Hants Oct '13)
Errors, Exceptions & Logging (PHP Hants Oct '13)
 
Handling error & exception in php
Handling error & exception in phpHandling error & exception in php
Handling error & exception in php
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)C++ idioms by example (Nov 2008)
C++ idioms by example (Nov 2008)
 
Php(report)
Php(report)Php(report)
Php(report)
 
Php operators
Php operatorsPhp operators
Php operators
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Last train to php 7
Last train to php 7Last train to php 7
Last train to php 7
 
Php7 HHVM and co
Php7 HHVM and coPhp7 HHVM and co
Php7 HHVM and co
 
More about PHP
More about PHPMore about PHP
More about PHP
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 

Similar to Surprise! It's PHP :) (unabridged)

Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
tutorialsruby
 

Similar to Surprise! It's PHP :) (unabridged) (20)

Introduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHPIntroduction to PHP - Basics of PHP
Introduction to PHP - Basics of PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Winter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHPWinter%200405%20-%20Beginning%20PHP
Winter%200405%20-%20Beginning%20PHP
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
FYBSC IT Web Programming Unit IV PHP and MySQL
FYBSC IT Web Programming Unit IV  PHP and MySQLFYBSC IT Web Programming Unit IV  PHP and MySQL
FYBSC IT Web Programming Unit IV PHP and MySQL
 
Giới thiệu PHP 7
Giới thiệu PHP 7Giới thiệu PHP 7
Giới thiệu PHP 7
 
Start using PHP 7
Start using PHP 7Start using PHP 7
Start using PHP 7
 
Zephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensionsZephir - A Wind of Change for writing PHP extensions
Zephir - A Wind of Change for writing PHP extensions
 
Introduction to php basics
Introduction to php   basicsIntroduction to php   basics
Introduction to php basics
 
Php7 hhvm and co
Php7 hhvm and coPhp7 hhvm and co
Php7 hhvm and co
 
Web Technology_10.ppt
Web Technology_10.pptWeb Technology_10.ppt
Web Technology_10.ppt
 
Intro to PHP
Intro to PHPIntro to PHP
Intro to PHP
 
The why and how of moving to php 5.4
The why and how of moving to php 5.4The why and how of moving to php 5.4
The why and how of moving to php 5.4
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
The new features of PHP 7 - Enrico Zimuel - Codemotion Milan 2016
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
PHP - Web Development
PHP - Web DevelopmentPHP - Web Development
PHP - Web Development
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Surprise! It's PHP :) (unabridged)

  • 1. Surprise! It's PHP  by Sharon Lee Levy [ unabridged PPT slideset ]
  • 2. Surprise! It's PHP  I. Introduction II. What's in a Name? III. The Mysterious Comma IV. Exploring Truth Values V. Additional Thoughts VI. Online Resources
  • 3. Concluding someone … designed PHP the way it is today. It has history and heritage. 3 Common PHP Mistake Flickr: by joanmaffeiart Mike Wallner See http://www.7php.com/php-interview-michael-wallner
  • 5. ... PHP seems to almost read your mind … 5 Flickr: by joanmaffeiart Rasmus Lerdorf See "The Early Days of PHP" interview
  • 6. 6 Flickr: by joanmaffeiart
  • 7. Artsy Hole Flickr: by estherase See Internals List: 3/2014
  • 8. A valid variable name starts with a letter or underscore… 8 ….. See Manual: Basics
  • 9. 9 I ♥ UTF-8 <?php $♥ = "love"; echo "I $♥ PHP!"; // I love PHP! See php_in_webapps.pdf; StackOverflow: unicode-identifiers-function-names…, JDN Interview of Andi Gutmans June 2014
  • 10. 10 <?php I ♥ UTF-8 const START= 0; $len = mb_strlen( "♥", '8bit' ); // 3 echo mb_substr( "♥", START, $len ); // ♥ // otherwise: [e2 99 a5]
  • 11. 11 <?php I ♥ UTF-8 class Test{ const AB♥ = "alphabet"; } $rc = new ReflectionClass("Test"); $t = array_keys( $rc->getConstants())[0]; $substr = substr( $t, -1,1 ); if ( $substr === "♥" ) { trigger_error(""♥" in "$t"",E_USER_ERROR ); } // [ PHP5.4 - 5.6 ]
  • 12. 12 <?php I ♥ UTF-8 class Test{ const AB♥ = "alphabet"; } $rc = new ReflectionClass("Test"); $t = array_keys( $rc->getConstants())[0]; $substr = mb_substr( $t, -1,1 ); // PHP 5.6 if ( $substr === "♥" ) { trigger_error(""♥" in "$t"", E_USER_ERROR); } // Fatal error: "♥" in "AB ♥" …
  • 13. That's not a hole in the design. Rasmus Lerdorf Internals List 3/12/2014 13
  • 15. The Mysterious Comma 15 echo_expr_list: <?php echo $var1, $var2, … See Manual: Operator Precedence  Left Associative  Many Uses  Has Least Precedence
  • 16. The Mysterious Comma 16 echo_expr_list: <?php echo $var1, $var2, … See PHP5.2 Changelog, lxr.php.net: echo_expr_list
  • 17. 17 <?php class Test { const ALPHA = 1, BETA = 2, GAMMA = 3; public $a = "apple", $b = "bread", $c = "candy"; // methods … } See StackOverflow: comma operator vs comma separator
  • 18. 18 $a = 10, $b = 20, $c = 30; See lxr.php.net: zend_language_parser.y
  • 19. 19 list( $a, $b, $c ) = array( 10, 20, 30 ); var_dump( $a, $b, $c ); // 10, 20, 30
  • 20. 20 Comma Operator  C  C++  Perl  PHP?  JavaScript See Wikipedia: Comma Operator
  • 21. JavaScript's Comma 21 // JavaScript var a = 2; var b = 4; var c = ( ++a, b * a ); // result: 12
  • 22. not likely to be implemented... bogussing. Internals List 2/1/2002 22
  • 23. 23 <?php for ( $a = 3, $b = 4; $a < $b; $a++; ) { $result = $a * $b; } var_dump( $result ); // int( 12 ) See doc.ic.ac.uk/lab/cplus/cstyle.html
  • 24. 24 <?php $a = 2; $b = 4; for ( ; ++$a, $a < $b; ) { $res = $a * $b; } var_dump( $res ); // int( 12 ) See comma.html
  • 26. 26 <?php echo null < -1 && null == 0; // true See PHP: a fractal of bad design
  • 27. 27 JavaScript's Null // JavaScript alert( null < -1 && null == 0 ); // false See Ecma-262.pdf; StackOverflow: why-null-0-null-0-but-not-null-0
  • 29. See StackOverflow uppercase-booleans-vs-lowercase-in-php and use-true-false-null; 29 TRUE, FALSE, and NULL keywords should always be fully uppercase. Coding Standards: CodeIgniter 2.20
  • 30. … true, false, null … should be all lower case, as upper case is reserved for constants. Coding Standards: FuelPHP 30
  • 31. Constants should always be … uppercase … This includes …PHP constants … TRUE, FALSE and NULL… Coding Standards: Drupal 31
  • 32. … PHP constants true, false, and null MUST be in lower case. 32 Coding Standard: PSR-2 See php-FIG: PSR_2 and 8/2014 discussion: http://tinyurl.com/mdasjak
  • 33. … in PHP, they are not constants; they are keywords mapping to language constructs. Matthew Weir O'Phinney Project Lead, Zend Framework, 2012 33 See Programming PHP by Rasmus Lerdorf, et al; Manual: define()
  • 34. To specify a boolean literal, use the keywords TRUE or FALSE. 34 See Bug report #67228
  • 35. To specify a boolean literal, use the constants TRUE or FALSE. 35 See Manual: Booleans
  • 36. 36 Technically … count more as reserved keywords than constants… Nikita Popov See Stackoverflow: NickiC 2/7/2014
  • 37. …case insensitive, to be downwards compatible and consistent with other languages… Zeev Suraski 37 See Internals List: 5/8/98
  • 38. 38 Flickr: by thebittenword.com
  • 39. Proof in the Pudding … 39 TRUE, FALSE, NULL  Usable as Identifiers  Ea. Has a Data Type See Manual: Reserved Constants, Language: Constants, Zend API: Hacking the Core of PHP; PHP Language Spec; 3v4l.org: V3H2n; Internals List: 7/16/2004
  • 40. 40 PERL Legacy Flickr: by ♫ Desmatron ♫
  • 41. PERL Legacy … truth value of expressions in PHP is calculated in a similar way to perl. 41 Zero Zero C false JavaScript false Perl false PHP false Python false Ruby true LISP true Scheme true  False: 0  True: !0  False: "" and "0"  True : 1 [<,>,<=,=>,==] PHP 3.0b4: lang-const.sgml
  • 42. 42 PERL Legacy  False: 0  True: !0 Perl  False: "" and "0"  True : 1 [<,>,<=,=>,==] See 3v4l.org: TrT4l; PerlMonks; What is true and false …
  • 43. 43 PERL Legacy Zero Zero C false JavaScript false Perl false PHP false Python false Ruby true LISP true Scheme true See StackOverflow: why-treat-0-as-true-in-ruby; is-false-0-and-true-1-in-python…
  • 44. True/False as C Macros 44 #define TRUE 261 #define FALSE 262
  • 45. True/False as Keywords 45 PHP3 Beta5 (2/98) PHP_TRUE 1 PHP_FALSE "" See Internals List 2/25/98 and bug report #354
  • 46. True/False as Keywords 46 PHP3 Beta5 (2/98) <IN_PHP>"FALSE" { phplval->value.strval = empty_string; phplval->strlen = 0; phplval->type = IS_STRING; return PHP_FALSE; } <IN_PHP>"TRUE" { phplval->value.lval = 1; phplval->type = IS_LONG; return PHP_TRUE; } See PHP3.0b6: language_scanner.lex, parser.h, language-parser.tab.c, configuration-parser.tab.c (and v.3.0, too)
  • 47. True/False as Keywords Made chown(), chgrp() and chmod() return TRUE/FALSE instead of 0/-1. PHP 3.0b5 ChangeLog 47 PHP3 Beta5 (2/98) See Internals List 2/25/98
  • 48. 48 PHP3 Constant  name: true, false, …  name_len  value value (pval) value: [1, ""] type: [IS_LONG, IS_STRING] See Internals List 5/8/98, 7/1/98 ; PHP3 constants.[ch], php.h; PHP3 Manual: Language constructs
  • 49. Until PHP3rc5 … $a = foo; // Notice: 'foo' is not a valid constant[ PHP3rc5+ ] // Notice: Use of undefined constant [ PHP4.3+ ] $a = "foo"; // mandatory: quoted 49 See Internals List: 5/24/98; PHP3: language-parser.tab.c, line 2642
  • 50. 50 Design & Consequences if ("5") { echo "Would print"; } if ("5"==TRUE) { echo "Would not print"; } Zeev Suraski General List: 7/1/98 See lang-const.html
  • 51. 51 PHP4 Reinvention zend_constant See PHP 4: zend_constants.[ch], zend.h value value (zval) value: [1, 0] type: IS_BOOL
  • 52. 52 PHP4 Reinvention <?php var_dump( (bool) 1); // bool( true ) See Andi Gutmans commit 4/71999: zend_constants.c; Extending and Embedding PHP by Sara Golemon, p 165; Internals List: 6/4/2000
  • 53. 53 <ST_IN_SCRIPTING>"NULL" { ZVAL_NULL(zendlval); return T_NULL; } <ST_IN_SCRIPTING>"FALSE" { ZVAL_FALSE(zendlval); return T_FALSE; } <ST_IN_SCRIPTING>"TRUE" { ZVAL_TRUE(zendlval); return T_TRUE; } Deja Vu? See php-cvs: 7/16/2004, Internals List: 07/16/2004, lxr.php.net: zend_language_scanner.l (History: Marcus Boerger 7/16/2004);
  • 54. Improved Booleans 54 PHP5.6: Z_LVAL_P(__z) = ((b) != 0); Z_LVAL_P(__z) = IS_BOOL; PHPNG: Z_TYPE_INFO_P(z) = (b) ? IS_TRUE : IS_FALSE; See PHP5.6 and PHPNG: zend_constants.h, zend_constants.c, zend_API.h; PHPNG: zend_types.h; also wiki.php.net: phpng; Internals List 11/10/2013
  • 55. … I misunderstood the expression evaluation of NULL/FALSE of PHP for my entire PHP life  Yasuo Ohgaki Internals List 11/10/2013 See blog.ohgaki.net: php-bool-null ( use Google translate); zend types.h: zval_bool and zend_vm_execute.h: isset/empty handler 55
  • 56. …please, don't make php programmers go berserk :) 56 Michal Vitecek See bug report: #4805
  • 57. 57 <?php echo ( !1 ); // PHP3: 0 echo ( !1 ); // PHP4: See Internals List: 6/4/2000; PHP3: language_parser.y and operators.c
  • 58. ZEND_API int boolean_not_function(zval *result, zval *op1) { zval op1_copy; zendi_convert_to_boolean(op1, op1_copy, result); 58 result->type = IS_BOOL; result->value.lval = !op1->value.lval; return SUCCESS; } See PHP4: zend_operators.c
  • 59. 59 … echo nothing at all? That's a bit Perlish for me! John Sutton Internals List, 7/1998
  • 60. 60 Invisible False <?php echo false; Opcode Return Value Operands ECHO false
  • 61. Invisible False ZEND_ECHO_SPEC_CONST_HANDLE R 61 zend_print_variable() zend_print_zval() zend_print_zval_ex() See lxr.php.net: zend_vm_execute.h
  • 62. 62 Invisible False zend_print_zval_ex(): zend_make_printable_zval() /* optimize away empty strings */ return 0 write_func() See lxr.php.net: zend.c#311; also: How-to-add-new-syntactic-features-to-PHP.html by Nikita Popov
  • 63. false has to be an empty string to correctly evaluate to false. 63 See Manual: Strings Rasmus Lerdorf Bug Report #49097
  • 64. 64 "0" <=> false <=> "0" "" => false => "0" See StackOverflow: why-doesnt-php-print-true-false
  • 65. 65 "" <=> false <=> "" "0" => false => "" => 0 => "0" See StackOverflow: php-get-bool-to-echo-false-when-false
  • 66. Flickr: by Tracey Stephens
  • 67. 67 <?php for ( $i = 1; ;$i++ ) { if ($i > 10) { break; } print $i; // 12345678910 } See PHP-3.0b4: lang-const.sgml, StackOverflow: what-does-for-mean, PHP5.6: zend_language_parser.y
  • 68. 68 for_expr: /* empty */ { $$.op_type = IS_CONST; Z_TYPE($$.u.constant) = IS_BOOL; Z_LVAL($$.u.constant) = 1; } See PHP-3.0b4: lang-const.sgml, StackOverflow: what-does-for-mean, PHP5.6: zend_language_parser.y
  • 69. 69 <?php $_POST[ "quantity" ] = "0"; if ( !empty( $_POST[ "quantity" ] ) ) { echo "It's not empty"; // PHP 3 } else { echo "It's empty"; // PHP 4 } See Internals List 5/11/2000, Manual: empty PHP3 and PHP4; bug report #: 2088
  • 70. 70 empty() considers "0" as non-empty, a value that … may come from an HTML form. See Internals List 5/11/2000, Manual: empty PHP3 and PHP4; bug report #: 2088
  • 71. 71 <?php var_dump( "", "0" ); // string(0) "", string(1) "" var_dump( (bool) "" ); // bool(false) var_dump( (bool) "0" ); // bool(true) var_dump( (bool) "0" ); // bool(false) See Manual: Booleans, bug report # 39904
  • 72. 72 Boolean "0" Perl false PHP false C true Python true Ruby true JavaScript true/false See Manual: Booleans, bug report #39904, perlmonks.org: what is true and false in perl, codepag.org: ScNhuOqY, 5zOu4NjN , Internals List: 2/25/98, 5/11/98, PHP3 ChangeLog: 5/11/98
  • 73. 73 JavaScript's "0" // JavaScript if ("0") alert(""0" is true"); // true if ("0" == false) alert(""0" is false"); // true See StackOverflow: why-does-0-a-b-behave-different-than-0-true-a-b
  • 74. "0" is no longer considered false … 74 - Zeev Suraski See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
  • 75. 75 …we're still thinking whether "0" should be considered false Andi & Zeev See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
  • 76. "" (string,false) <=> 0 (int, false) <=> "0"(string,true) 76 See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
  • 77. ***NOTE*** Changed "0" to mean FALSE again 77 See Internals List: 2/25/98, 5/11/98 and PHP3 ChangeLog: 5/11/98
  • 78. 78 <?php echo empty( "" ); // 1 echo empty( "0" ); // 1 echo (int) ( "" == "0" ); // 0 See 3v4l.org: U0G6L#v430, Manual: empty, Internals List: 8/20/2014
  • 79. 79 <?php $a = "0.0"; $b = 0.0; var_dump( $a == $b ); // true var_dump( empty( $a ) ); // false See Bug report #: 60402 and The Manual; pickingUpPerl_5.html; PHP4 Manual: migration4.empty.html
  • 80. 80 <?php $items = false; echo count( $items ); // 1 $it = new EmptyIterator; var_dump( count( $it ) ); // 1 See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
  • 81. 81 Counts all elements in an array, or something in an object PHP5 Manual See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
  • 82. Returns the number of elements in var, … typically an array … anything else will have one element ... 82 PHP3 Manual See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
  • 83. 83 switch (Z_TYPE_P(array)) { case IS_NULL: RETURN_LONG(0); break; case IS_ARRAY: [snipped] case IS_OBJECT: /* handler defined? */ /* If Countable, call count() method */ default: RETURN_LONG(1); break; } See lxr.php.net: array.c, Bug reports #: 46322 and #: 60577
  • 85. Dec 28, 1999 (Thies Arntzen) new constant SQL_NULL PHP4.0b4: (Feb 2000) Added new NULL constant (Zeev, Zend Engine) 85 About Null c.value.value.lval = 0; c.value.type = IS_LONG; See Thies Arntzen's Commit, PHP4 Changelog; PHP 4: zend_constants.c; bug report: #67562
  • 86. 86 About NULL zend_constant value value (zval) vvaalluuee:: [[ uunnsseett ]] ttyyppee:: IISS__NNUULLLL null is not a value, was never meant to be a value, and won't be a value. Zeev Suraski Internals List 8/17/2003 See PHP4.0b4 Changelog; PHP 4: zend_constants.c; bug report: #67562
  • 87. 87 <?php echo (int) null; // 0 See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
  • 88. 88 // Dec. 31, 1999 – introduced IS_UNSET - Zeev Suraski convert_to_long_base( zval *op, int base ): switch (op->type) { case IS_UNSET: op->value.lval = 0; break; See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
  • 89. 89 // Jan 4, 2000: IS_UNSET => IS_NULL - Andi Gutmans convert_to_long_base( zval *op, int base ): switch (op->type) { case IS_NULL: op->value.lval = 0; break; See lxr.php.net: (PHP5.2) zend_operators.c annotated and history.
  • 90. 90 <?php $a = "apple"; $a = null; echo isset( $a ); // false unset( $a ); echo isset( $a ); // false echo isset( $b ); // false See Internals List: 7/3/2014
  • 91. 91 <?php // null detection: echo isset( $var ); // false echo empty( $var ); // true See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
  • 92. isset( $var ) && $var == NULL // Internals List !isset($var) || $var == false // The Manual ZVAL_BOOL(&EX_T(opline->result.var).tmp_var, 1); 92 <?php /* if (opline->extended_value & ZEND_ISEMPTY) */ { if (!isset || !i_zend_is_true(*value)) { See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
  • 93. 93 <?php // null detection: echo is_null( $var ); // true, but… echo (null === $var ); // ditto See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
  • 94. 94 # Perl: unless( defined( $var ) ) { # unless == if ! print "$var is undefined"; } See Internals List: 7/3/2014; Nikita Popov RFC: Abstract Syntax Tree
  • 95. 95 <?php See StackOverflow: Eisberg $n = null; var_dump( array_key_exists( 'n', get_defined_vars() ) ); // true
  • 96. 96 <?php See StackOverflow: Eisberg $n = null; unset( $n ); var_dump( array_key_exists( 'n', get_defined_vars() ) ); // false
  • 97. 97 <?php $count = count( get_defined_vars() ); $myvar = null; $recount = get_defined_vars(); var_dump( array_slice( $recount, $count + 1) ); // array(1) { ["myvar"]=> NULL } See StackOverflow: Eisberg
  • 98. 98 <?php See Internals List 6/5/2005 $count = null; $count++; var_dump( $count ); // int(1) $count--; var_dump( $count ); // null
  • 99. 99 // int increment_function case IS_BOOL: op1->value.lval++; op1->type = IS_LONG; break; case IS_NULL: op1->value.lval = 1; op1->type.lval = IS_LONG; // int decrement_function case IS_BOOL: op1->value.lval--; op1->type = IS_LONG; break; case IS_NULL: op1->value.lval = -1; op1->type = IS_LONG; Excerpted from Johannes Schlueter's Patch; see also Tjerk Meesters' RFC:Normalize increment and decrement operators
  • 100. 100 // JavaScript: var m = null, n = null; alert( ++m ); // 1 alert( --n ); // -1 var e = true, f = false; alert( ++e ); // 2 alert( --f ); // -1
  • 101. 101 <?php // * Sum byte values from position x in $str function sum( $str, $x ) { $sum = 0; for ( $max = strlen( $str ); $x < $max; ++$x ) { $sum += ord( $str[ $x ] ); } return $sum; } $str = 'Hello, Dolly'; echo sum( $str, strpos( $str, 'F' ) ); // typo: sh/b 'D' See Internals List 6/5/2005, Johannes Schlueter's Patch and Tjerk Meesters' RFC: Normalize increment and decrement operators
  • 102. Compare NULL & Any 102  Convert both sides to bool  FALSE < TRUE See Internals List 11/10/2013; Manual: comparison operators: PHP5.3 and PHP5.5
  • 103. Compare NULL & Any 103 <?php echo null < -1; echo false < true; See Internals List 11/10/2013; Manual: comparison operators: PHP5.3 and PHP5.5
  • 104. Code Compliance? 104 <?php echo null < -1; Opcode Return Value Operands IS_SMALLER ~0 null, -1
  • 105. 105 Is_Smaller ZEND_IS_SMALLER_SPEC_CONST_CONST_HANDLE R ZVAL_BOOL(result, fast_is_smaller_function: compare_function(result, null, -1) … ) See PHP5.6: zend_vm_execute.h, zend_operators.h,
  • 106. PHP4: Compare_Function /* op1->type == IS_NULL */ zendi_convert_to_boolean(op1, op1_copy, result); zendi_convert_to_boolean(op2, op2_copy, result); result->type = IS_LONG; result->value.lval = NORMALIZE_BOOL( op1->value.lval-op2->value.lval ); 106 return SUCCESS; See zend_operators.c, PHP4
  • 107. PHP4: Compare_Function /* op1->type == IS_NULL */ zendi_convert_to_boolean(op1, op1_copy, result); zendi_convert_#define to_NORMALIZE_boolean(op2, op2_BOOL(copy, n) result); result->type = IS_LONG; result->value.lval = NORMALIZE_BOOL( op1->value.lval-op2->value.lval ); 107 return SUCCESS; ((n) ? (((n)>0) ? 1 : -1) : 0) See zend_operators.c, PHP4
  • 108. PHP5: Compare_Function if (Z_TYPE_P(op1) == IS_NULL) { zendi_convert_to_boolean(op2, op2_copy, result); ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0); return SUCCESS; } 108 * See lxr.php.net: PHP_5_6/Zend/zend_operators.c#1593
  • 109. 109 Is_Smaller Result ZEND_IS_SMALLER_SPEC_CONST_CONST_HAND LER ZVAL_BOOL(result, fast_is_smaller_function: compare_function(result, null, -1) return Z_LVAL_P(result) < 0 ) See PHP5.6: zend_vm_execute.h, zend_operators.h,
  • 110. 110 Flickr: by fxalau
  • 111. 111 <?php var_dump( null == false ); var_dump( false == 0 ); var_dump( null == 0 ); // true
  • 112. Internals of Equality 112 <?php null == 0; // True Opcode Return Value Operands IS_EQUAL ~0 null, 0 Recommended reading: Anatomy of Equals by A. Ferrara
  • 113. compare_function(result, null, 0); … 113 Is_Equal ZEND_IS_EQUAL_SPEC_CONST_CONST_HANDLER ZVAL_BOOL( result, fast_equal_function(): ) See lxr.php.net: PHP_5_6/Zend/zend_vm_execute.h#3475
  • 114. PHP5: Compare_Function if (Z_TYPE_P(op1) == IS_NULL) { zendi_convert_to_boolean(op2, op2_copy, result); ZVAL_LONG(result, Z_LVAL_P(op2) ? -1 : 0); return SUCCESS; } 114 See lxr.php.net: PHP_5_6/Zend/zend_operators.c#1593; PHP5.2: zend_operators.c
  • 115. compare_function(result, null, 0); return Z_LVAL_P(result) == 0; 115 Is_Equal ZEND_IS_EQUAL_SPEC_CONST_CONST_HANDLER ZVAL_BOOL( result, fast_equal_function(): ) See lxr.php.net: PHP_5_6/Zend/zend_vm_execute.h#3475
  • 116. 116
  • 117. Resources  3v4l.org  codepad.org  lxr.php.net  markmail.org: "PHP Internals List"  museum.php.net  slevy1.wordpress.com

Editor's Notes

  1. Welcome! Whoami
  2. Talk explores basic notions in PHP fr holistic perspective Who knows what surprises we may encounter … Benefit: help avoid making common PHP mistake
  3. PHPland – an idllyic place? Maybe …
  4. Early adoptees shared Lerdorf&amp;apos;s enthusiasm Like Rasmus we knew C, Perl and JAVA -- all langs impacting PHP&amp;apos;s design Today&amp;apos;s programmer: Has s/he heard of Perl, let alone know it? Ignorance of languages impacting PHP may result =&amp;gt; metaphor about PHP and vacuum cleaner.
  5. Early adoptees shared Lerdorf&amp;apos;s enthusiasm Like Rasmus we knew C, Perl and JAVA -- all langs impacting PHP&amp;apos;s design Today&amp;apos;s programmer: Has s/he heard of Perl, let alone know it? Ignorance of languages impacting PHP may result =&amp;gt; metaphor about PHP and vacuum cleaner.
  6. Early part of this year someone alleged on Internals List: a hole in PHP&amp;apos;s design! Response to a discussion about bizarre PHP identifiers
  7. Definition fr Manual Begs question: what consittitues a letter ...
  8. Code more than decorative – executable! When did PHP start supporting Unicode? PHP does not natively support unicode nor will it per A Gutmans Standard String library funcs unaware of multibyte chars PHP does not natively support unicode nor willl it per A Gutmans! Heart symbol when utf8-encoded (default) composed of multiple bytes whose hex values all coincidentally fall within acceptable range [a-zA-Z0-9] and ascii(128-255) of numerical values for bytes. Can use multibyte string (aka mbstring) ext. (recc&amp;apos;d by Drupal) to disallow unicode char or rather code point.
  9. Code more than decorative – executable! When did PHP start supporting Unicode? PHP does not natively support unicode nor will it per A Gutmans Standard String library funcs unaware of multibyte chars PHP does not natively support unicode nor willl it per A Gutmans! Heart symbol when utf8-encoded (default) composed of multiple bytes whose hex values all coincidentally fall within acceptable range [a-zA-Z0-9] and ascii(128-255) of numerical values for bytes. Can use multibyte string (aka mbstring) ext. (recc&amp;apos;d by Drupal) to disallow unicode char or rather code point.
  10. Code more than decorative – executable! When did PHP start supporting Unicode? PHP does not natively support unicode nor will it per A Gutmans Standard String library funcs unaware of multibyte chars PHP does not natively support unicode nor willl it per A Gutmans! Heart symbol when utf8-encoded (default) composed of multiple bytes whose hex values all coincidentally fall within acceptable range [a-zA-Z0-9] and ascii(128-255) of numerical values for bytes. Can use multibyte string (aka mbstring) ext. (recc&amp;apos;d by Drupal) to disallow unicode char or rather code point.
  11. Code more than decorative – executable! When did PHP start supporting Unicode? PHP does not natively support unicode nor will it per A Gutmans Standard String library funcs unaware of multibyte chars PHP does not natively support unicode nor willl it per A Gutmans! Heart symbol when utf8-encoded (default) composed of multiple bytes whose hex values all coincidentally fall within acceptable range [a-zA-Z0-9] and ascii(128-255) of numerical values for bytes. Can use multibyte string (aka mbstring) ext. (recc&amp;apos;d by Drupal) to disallow unicode char or rather code point.
  12. Is there a hole in PHP&amp;apos;s design? Debatable. Per Lerdorf: No b/c in early days focus on not arbitrarily limiting identifiers. Any char conflicting with PHP disallowed. Think &amp;lt;space&amp;gt; ; , { } ( ) etc.
  13. Speaking of the comma … Ubiquitous so-called operator How well do we really understand it?
  14. In C, comma has least precedence as an op PHP inherits its syntax from C In PHP more of a separator: used for lists and declarations: Example - echo_list: echo $var1, $var2, …
  15. In C, comma has least precedence as an op PHP inherits its syntax from C In PHP more of a separator: used for lists and declarations: Example - echo_list: echo $var1, $var2, …
  16. Comma as separator specifies: &amp;quot;c&amp;quot;-type constants declared as are class properties (a declaration specifies type and identifier to inform compiler about element) Parse error msg: unexpected &amp;apos;,&amp;apos;
  17. Comma as separator specifies: &amp;quot;c&amp;quot;-type constants declared as are class properties (a declaration specifies type and identifier to inform compiler about element) Parse error msg: unexpected &amp;apos;,&amp;apos;
  18. Comma as separator specifies: &amp;quot;c&amp;quot;-type constants declared as are class properties (a declaration specifies type and identifier to inform compiler about element) Parse error msg: unexpected &amp;apos;,&amp;apos;
  19. Does PHP belong? The other langs support a binary comma operator JS example …
  20. processes 1st op, discards it, but side-effect (incremented var) captured and used in 2nd expr which evaluates and its result is usable and gets assigned to x. Try in your browser: javascript: if (a=1,b=2) alert(a+b);
  21. Same day requested, prompty rejected Smart decision or too conservative?
  22. Binary comma best in for-loops according to some authorities for(initialization; condition; iteration_expression) Best for initialization expression altho&amp;apos; may be used for multiple operations, too.
  23. Binary comma best in for-loops according to some authorities for(initialization; condition; iteration_expression) Best for initialization expression altho&amp;apos; may be used for multiple operations, too.
  24. PHP&amp;apos;s logic stands on a slippery slope per its detractors
  25. Use cases? Eevee in his infamous rant remarks that first comparison is inconsistent with the 2nd.
  26. To make matters worse, JavaScript does things opposite of PHP. How JS does it …
  27. Who&amp;apos;s got it rt and who&amp;apos;s got it wrong? It&amp;apos;s really about different design approaches. Essential question: How well do we understand the truth values and null in PHP?
  28. T/F/N: keywords or constants? Does it matter? Yes b/c that perception determines: How we express them Availability of identifiers PSR-2 from PHP Framework Interop[erability] Group (FIG) [Proposing a Standards Recommendation (PSR)] Contacted Phil Sturgeon, prominent FIG member. He explained: Some saw constants, others felt they were more like keywords, Standard result of vote and Not going to change! Never say never : think case of pow operator and Jim Winstead. Per Sturgeon&amp;apos;s suggestion I discuss further on php-FIG. After a flurry of emails (19) exchanged, the next day David Grudl forked php-FIG and created php-fg which has its own PGS-2: T&amp;F Constants;upper or lowercase fine. A joke? But then every joke may be ½ serious … MWOP take How does such a misunderstanding arise ? Maybe b/c of one book: Programming PHP by Father of PHP himself, Rasmus Lerdor et al Not one erratum despite 3 eds in re TRUE/FALSE designated as keywords Arg for lowercasing: PHP API var_dump,var_export follows ZE Retort: funcs result do what code would do if constants accessed, such that the ZE would return lowercased forms – all CI constants stored in lowercase. Orginally all constants were lowercased (see PHP3) but at some pt decision to only lowercase CI constants. Uppercase convenience for user eyes whereas lowercasing TRUE, FALSE and NULL for hashtable storage may be related to processing or may even be an arbitrary decision with no distinct advantage. While they may seem like keywords use kw as identifiers (except for variables b/c $ let&amp;apos;s us get alway with that) http://3v4l.org/V3H2n, but with constants we may! ==================================================== Option: could add them back as keywords and deprecate and remove the alternate syntax:endfor,endswitch,endif,endforeach (and their has been discussion on Internals List recently about deprecating such keywords and then removing them.
  29. T/F/N: keywords or constants? Does it matter? Yes b/c that perception determines: How we express them Availability of identifiers PSR-2 from PHP Framework Interop[erability] Group (FIG) [Proposing a Standards Recommendation (PSR)] Contacted Phil Sturgeon, prominent FIG member. He explained: Some saw constants, others felt they were more like keywords, Standard result of vote and Not going to change! Never say never : think case of pow operator and Jim Winstead. Per Sturgeon&amp;apos;s suggestion I discuss further on php-FIG. After a flurry of emails (19) exchanged, the next day David Grudl forked php-FIG and created php-fg which has its own PGS-2: T&amp;F Constants;upper or lowercase fine. A joke? But then every joke may be ½ serious … MWOP take How does such a misunderstanding arise ? Maybe b/c of one book: Programming PHP by Father of PHP himself, Rasmus Lerdor et al Not one erratum despite 3 eds in re TRUE/FALSE designated as keywords Arg for lowercasing: PHP API var_dump,var_export follows ZE Retort: funcs result do what code would do if constants accessed, such that the ZE would return lowercased forms – all CI constants stored in lowercase. Orginally all constants were lowercased (see PHP3) but at some pt decision to only lowercase CI constants. Uppercase convenience for user eyes whereas lowercasing TRUE, FALSE and NULL for hashtable storage may be related to processing or may even be an arbitrary decision with no distinct advantage. While they may seem like keywords use kw as identifiers (except for variables b/c $ let&amp;apos;s us get alway with that) http://3v4l.org/V3H2n, but with constants we may! ==================================================== Option: could add them back as keywords and deprecate and remove the alternate syntax:endfor,endswitch,endif,endforeach (and their has been discussion on Internals List recently about deprecating such keywords and then removing them.
  30. T/F/N: keywords or constants? Does it matter? Yes b/c that perception determines: How we express them Availability of identifiers PSR-2 from PHP Framework Interop[erability] Group (FIG) [Proposing a Standards Recommendation (PSR)] Contacted Phil Sturgeon, prominent FIG member. He explained: Some saw constants, others felt they were more like keywords, Standard result of vote and Not going to change! Never say never : think case of pow operator and Jim Winstead. Per Sturgeon&amp;apos;s suggestion I discuss further on php-FIG. After a flurry of emails (19) exchanged, the next day David Grudl forked php-FIG and created php-fg which has its own PGS-2: T&amp;F Constants;upper or lowercase fine. A joke? But then every joke may be ½ serious … MWOP take How does such a misunderstanding arise ? Maybe b/c of one book: Programming PHP by Father of PHP himself, Rasmus Lerdor et al Not one erratum despite 3 eds in re TRUE/FALSE designated as keywords Arg for lowercasing: PHP API var_dump,var_export follows ZE Retort: funcs result do what code would do if constants accessed, such that the ZE would return lowercased forms – all CI constants stored in lowercase. Orginally all constants were lowercased (see PHP3) but at some pt decision to only lowercase CI constants. Uppercase convenience for user eyes whereas lowercasing TRUE, FALSE and NULL for hashtable storage may be related to processing or may even be an arbitrary decision with no distinct advantage. While they may seem like keywords use kw as identifiers (except for variables b/c $ let&amp;apos;s us get alway with that) http://3v4l.org/V3H2n, but with constants we may! ==================================================== Option: could add them back as keywords and deprecate and remove the alternate syntax:endfor,endswitch,endif,endforeach (and their has been discussion on Internals List recently about deprecating such keywords and then removing them.
  31. T/F/N: keywords or constants? Does it matter? Yes b/c that perception determines: How we express them Availability of identifiers PSR-2 from PHP Framework Interop[erability] Group (FIG) [Proposing a Standards Recommendation (PSR)] Contacted Phil Sturgeon, prominent FIG member. He explained: Some saw constants, others felt they were more like keywords, Standard result of vote and Not going to change! Never say never : think case of pow operator and Jim Winstead. Per Sturgeon&amp;apos;s suggestion I discuss further on php-FIG. After a flurry of emails (19) exchanged, the next day David Grudl forked php-FIG and created php-fg which has its own PGS-2: T&amp;F Constants;upper or lowercase fine. A joke? But then every joke may be ½ serious … MWOP take How does such a misunderstanding arise ? Maybe b/c of one book: Programming PHP by Father of PHP himself, Rasmus Lerdor et al Not one erratum despite 3 eds in re TRUE/FALSE designated as keywords Arg for lowercasing: PHP API var_dump,var_export follows ZE Retort: funcs result do what code would do if constants accessed, such that the ZE would return lowercased forms – all CI constants stored in lowercase. Orginally all constants were lowercased (see PHP3) but at some pt decision to only lowercase CI constants. Uppercase convenience for user eyes whereas lowercasing TRUE, FALSE and NULL for hashtable storage may be related to processing or may even be an arbitrary decision with no distinct advantage. While they may seem like keywords use kw as identifiers (except for variables b/c $ let&amp;apos;s us get alway with that) http://3v4l.org/V3H2n, but with constants we may! ==================================================== Option: could add them back as keywords and deprecate and remove the alternate syntax:endfor,endswitch,endif,endforeach (and their has been discussion on Internals List recently about deprecating such keywords and then removing them.
  32. T/F/N: keywords or constants? Does it matter? Yes b/c that perception determines: How we express them Availability of identifiers PSR-2 from PHP Framework Interop[erability] Group (FIG) [Proposing a Standards Recommendation (PSR)] Contacted Phil Sturgeon, prominent FIG member. He explained: Some saw constants, others felt they were more like keywords, Standard result of vote and Not going to change! Never say never : think case of pow operator and Jim Winstead. Per Sturgeon&amp;apos;s suggestion I discuss further on php-FIG. After a flurry of emails (19) exchanged, the next day David Grudl forked php-FIG and created php-fg which has its own PGS-2: T&amp;F Constants;upper or lowercase fine. A joke? But then every joke may be ½ serious … MWOP take How does such a misunderstanding arise ? Maybe b/c of one book: Programming PHP by Father of PHP himself, Rasmus Lerdor et al Not one erratum despite 3 eds in re TRUE/FALSE designated as keywords Arg for lowercasing: PHP API var_dump,var_export follows ZE Retort: funcs result do what code would do if constants accessed, such that the ZE would return lowercased forms – all CI constants stored in lowercase. Orginally all constants were lowercased (see PHP3) but at some pt decision to only lowercase CI constants. Uppercase convenience for user eyes whereas lowercasing TRUE, FALSE and NULL for hashtable storage may be related to processing or may even be an arbitrary decision with no distinct advantage. While they may seem like keywords use kw as identifiers (except for variables b/c $ let&amp;apos;s us get alway with that) http://3v4l.org/V3H2n, but with constants we may! ==================================================== Option: could add them back as keywords and deprecate and remove the alternate syntax:endfor,endswitch,endif,endforeach (and their has been discussion on Internals List recently about deprecating such keywords and then removing them.
  33. Truth: We&amp;apos;ve also been misled by Manual. Consider source code going back to even before official release of PHP3 So, I filed a bug report; docs have now been fixed to reflect the truth. Nitkita&amp;apos;s thoughts … The constants seem more like keywords semantically, e.g. True == true, like &amp;quot;echo&amp;quot; merely returns T_ECHO as echo means echo. When originally appeared in PHP3 perceived officially as constants; Zeev Suraski who created them as CI (BC compatible and consistent w/other languages) urged that they be uppercased.
  34. Truth: We&amp;apos;ve also been misled by Manual. Consider source code going back to even before official release of PHP3 So, I filed a bug report; docs have now been fixed to reflect the truth. Nitkita&amp;apos;s thoughts … The constants seem more like keywords semantically, e.g. True == true, like &amp;quot;echo&amp;quot; merely returns T_ECHO as echo means echo. When originally appeared in PHP3 perceived officially as constants; Zeev Suraski who created them as CI (BC compatible and consistent w/other languages) urged that they be uppercased.
  35. Truth: We&amp;apos;ve also been misled by Manual. Consider source code going back to even before official release of PHP3 So, I filed a bug report; docs have now been fixed to reflect the truth. Nitkita&amp;apos;s thoughts … The constants seem more like keywords semantically, e.g. True == true, like &amp;quot;echo&amp;quot; merely returns T_ECHO as echo means echo. When originally appeared in PHP3 perceived officially as constants; Zeev Suraski who created them as CI (BC compatible and consistent w/other languages) urged that they be uppercased.
  36. Truth: We&amp;apos;ve also been misled by Manual. Consider source code going back to even before official release of PHP3 So, I filed a bug report; docs have now been fixed to reflect the truth. Nitkita&amp;apos;s thoughts … The constants seem more like keywords semantically, e.g. True == true, like &amp;quot;echo&amp;quot; merely returns T_ECHO as echo means echo. When originally appeared in PHP3 perceived officially as constants; Zeev Suraski who created them as CI (BC compatible and consistent w/other languages) urged that they be uppercased.
  37. http://php.net/manual/en/reserved.constants.php: TRUE FALSE NULL http://php.net/manual/en/language.constants.php: &amp;quot;By convention, constant identifiers are always uppercase.&amp;quot; PHP4 and ZE1: boolean constants; Manual calls them &amp;quot;true constants&amp;quot;. As oppposed to what? Variables! They are actually: Static read-only variables Stored in hashtable, globally accessible CI unlike other constants for sake of BC and consistency w/other langs (Zeev) Don&amp;apos;t need and shouldn&amp;apos;t use $ to use them PHP Lang Spec (courtesy FB,SG) confirms they are constants. This issue should not be ambiguous, but rather straightforward and very clear. the booleans sure seem like keywords so could add them back as keywords and deprecate and remove the alternate syntax: endfor,endswitch,endif,endforeach
  38. http://php.net/manual/en/reserved.constants.php: TRUE FALSE NULL http://php.net/manual/en/language.constants.php: &amp;quot;By convention, constant identifiers are always uppercase.&amp;quot; PHP4 and ZE1: boolean constants; Manual calls them &amp;quot;true constants&amp;quot;. As oppposed to what? Variables! They are actually: Static read-only variables Stored in hashtable, globally accessible CI unlike other constants for sake of BC and consistency w/other langs (Zeev) Don&amp;apos;t need and shouldn&amp;apos;t use $ to use them PHP Lang Spec (courtesy FB,SG) confirms they are constants. This issue should not be ambiguous, but rather straightforward and very clear. the booleans sure seem like keywords so could add them back as keywords and deprecate and remove the alternate syntax: endfor,endswitch,endif,endforeach
  39. Determining TRUE and FALSE … Statement from early version version pre-release of PHP3 Expr == 0, false else !0 == true in PHP; Initially no explicit way to handle true,false What Perl does: Defines false, then derives true, so neg numbers are true, too! [Ruby: only false and null are false; if exists then true LISP: only Nil (empty list) is false; Scheme #f is false] Boolean 0 value matter of convention. [Scheme: dialect of LISP; see http://c2.com/cgi/wiki?LispSchemeDifferences]
  40. Determining TRUE and FALSE … Statement from early version version pre-release of PHP3 Expr == 0, false else !0 == true in PHP; Initially no explicit way to handle true,false What Perl does: Defines false, then derives true, so neg numbers are true, too! [Ruby: only false and null are false; if exists then true LISP: only Nil (empty list) is false; Scheme #f is false] Boolean 0 value matter of convention. [Scheme: dialect of LISP; see http://c2.com/cgi/wiki?LispSchemeDifferences]
  41. Determining TRUE and FALSE … Statement from early version version pre-release of PHP3 Expr == 0, false else !0 == true in PHP; Initially no explicit way to handle true,false What Perl does: Defines false, then derives true, so neg numbers are true, too! [Ruby: only false and null are false; if exists then true LISP: only Nil (empty list) is false; Scheme #f is false] Boolean 0 value matter of convention. [Scheme: dialect of LISP; see http://c2.com/cgi/wiki?LispSchemeDifferences]
  42. Determining TRUE and FALSE … Statement from early version version pre-release of PHP3 Expr == 0, false else !0 == true in PHP; Initially no explicit way to handle true,false What Perl does: Defines false, then derives true, so neg numbers are true, too! [Ruby: only false and null are false; if exists then true LISP: only Nil (empty list) is false; Scheme #f is false] Boolean 0 value matter of convention. [Scheme: dialect of LISP; see http://c2.com/cgi/wiki?LispSchemeDifferences]
  43. Macro definition,substitution similar to PHP constant; K&amp;R: symbolic constants In Perl and JS &amp;quot;&amp;quot; means false in boolean context Big benefit: now functions could return true and false instead of 0 &amp; -1 as PHP/FI. Seems incongruous 1 and &amp;quot;&amp;quot; but exemplifies PHP pragmatism Reason: Internally, follows Perl which returns &amp;quot;&amp;quot; for when false (internally 0) is in string context
  44. Macro definition,substitution similar to PHP constant; K&amp;R: symbolic constants In Perl and JS &amp;quot;&amp;quot; means false in boolean context Big benefit: now functions could return true and false instead of 0 &amp; -1 as PHP/FI. Seems incongruous 1 and &amp;quot;&amp;quot; but exemplifies PHP pragmatism Reason: Internally, follows Perl which returns &amp;quot;&amp;quot; for when false (internally 0) is in string context
  45. Macro definition,substitution similar to PHP constant; K&amp;R: symbolic constants In Perl and JS &amp;quot;&amp;quot; means false in boolean context Big benefit: now functions could return true and false instead of 0 &amp; -1 as PHP/FI. Seems incongruous 1 and &amp;quot;&amp;quot; but exemplifies PHP pragmatism Reason: Internally, follows Perl which returns &amp;quot;&amp;quot; for when false (internally 0) is in string context
  46. Macro definition,substitution similar to PHP constant; K&amp;R: symbolic constants In Perl and JS &amp;quot;&amp;quot; means false in boolean context Big benefit: now functions could return true and false instead of 0 &amp; -1 as PHP/FI. Seems incongruous 1 and &amp;quot;&amp;quot; but exemplifies PHP pragmatism Reason: Internally, follows Perl which returns &amp;quot;&amp;quot; for when false (internally 0) is in string context
  47. May 8 &amp;apos;98: Zeev Suraski figured out how to implement constants in PHP Changed true and false from keywords to constants backwards compatible and with a usage like other languages. True and false among first constants he created, too. True and false as keywords eliminated – one of the design goals of PHP is to minimize keywords. See constants.h for php3_constant: PHP.h: typedef struct _pval_struct pval; struct _pval_struct typedef union yystype_value; PHP3: (6/98)
  48. Undocumented feature now impeded by new constants feature, ergo notice.
  49. Undocumented feature now impeded by new constants feature, ergo notice. Not Boolean Constants! 1st – example of truth-expression context 2nd would be superfluous if only TRUE was really a boolean instead: 2nd &amp;quot;5&amp;quot; == 1 (NO!) &amp;quot;…PHP doesn&amp;apos;t have a dedicated boolean type …&amp;quot; (PHP3 Manual)
  50. http://lxr.php.net/xref/PHP_5_2/Zend/zend_constants.c?a=true&amp;r=573b46022c46ab41a879c23f4ea432dd4d0c102e: Andi Gutmans commited true and false as boolean constants 4/7/99, as part of the new Zend engine. PHP4: 5/2000 – PHP projects&amp;apos; greatest strength: willingness to change. That kind of flexibility has contributed to its longevity. zend_register_constant(): lowercased name stored in HashTable Booleans arrive: may 2000 per http://en.wikipedia.org/wiki/PHP
  51. http://lxr.php.net/xref/PHP_5_2/Zend/zend_constants.c?a=true&amp;r=573b46022c46ab41a879c23f4ea432dd4d0c102e: Andi Gutmans commited true and false as boolean constants 4/7/99, as part of the new Zend engine. PHP4: 5/2000 – PHP projects&amp;apos; greatest strength: willingness to change. That kind of flexibility has contributed to its longevity. zend_register_constant(): lowercased name stored in HashTable Booleans arrive: may 2000 per http://en.wikipedia.org/wiki/PHP
  52. Marcus Boerger (SPL) sought to optimize PHP in 2004 PHP5.1 by eliminating FETCH_CONSTANT opcode generating for accessing true,false and null He modified zend_language_scanner.l and zend_language_parser.y to re-implement as keywords true,false and null and thereby eliminate opcode. (7/16/2004; [see http://lxr.php.net/xref/PHP_5_3/Zend/zend_language_scanner.l?r=86d46f7cc10adbdef89968cde921bb6e975feeb7#1307; also see http://lxr.php.net/xref/PHP_5_3/Zend/zend_language_parser.y?r=86d46f7cc10adbdef89968cde921bb6e975feeb7#145 – for the tokens (7/16/2004)] And: 8/2/2004 reverted – after &amp;lt; 3wks, i.e. 2wk &amp; 4 days) Sterling Hughes forced Boerger&amp;apos;s to revert patch b/c &amp;quot;…the performance increase is neglible - its a *bad* optimization. &amp;quot; (see http://markmail.org/message/w66pun34oxnmxo6c) [http://lxr.php.net/history/PHP_5_2/Zend/zend_language_scanner.l (History: Marcus Boerger: 8/2/2004 reverted everything but noted # - NULL can be reintroduced later when needed Andi G had been in favor of turning T/F/N into keywords (see http://markmail.org/message/q6wfe2cm465ofd6o).
  53. Today&amp;apos;s code is similar to PHP3 and PHP4 but makes more clear that the fundamental meaning of 0 is False and not the other way around (which a core contributor confessed he had mis-aprehended fundamental meaning of TRUE and FALSE for &amp;quot;…my entire PHP life…&amp;quot;.
  54. Thought that fundamentally FALSE means 0 and not the other way around.
  55. The consternation surrounding display of FALSE …
  56. PHP: boolean not; C: logical negation ! Creates boolean context and reverses boolean value, ie true-&amp;gt;false and false-&amp;gt;true ! : convert operand to Boolean: PHP3 0/1; expressions (0) == false and (1) == true in Perl, C and PHP3 Type s/b long_int PHP4 0/1 IS_BOOL Then apply logical negation so true-&amp;gt;false and false-&amp;gt;true False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false
  57. PHP: boolean not; C: logical negation ! Creates boolean context and reverses boolean value, ie true-&amp;gt;false and false-&amp;gt;true ! : convert operand to Boolean: PHP3 0/1; expressions (0) == false and (1) == true in Perl, C and PHP3 Type s/b long_int PHP4 0/1 IS_BOOL Then apply logical negation so true-&amp;gt;false and false-&amp;gt;true False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false
  58. PHP: boolean not; C: logical negation ! Creates boolean context and reverses boolean value, ie true-&amp;gt;false and false-&amp;gt;true ! : convert operand to Boolean: PHP3 0/1; expressions (0) == false and (1) == true in Perl, C and PHP3 Type s/b long_int PHP4 0/1 IS_BOOL Then apply logical negation so true-&amp;gt;false and false-&amp;gt;true False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false
  59. Cascade of function calls: ECHO opcode -&amp;gt; ZEND_ECHO_SPEC_CONST_HANDLER -&amp;gt;zend_print_variable()-&amp;gt;zend_print_zval-&amp;gt;zend_print_zval_ex-&amp;gt; False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false write_func() only display strings that are non-empty.
  60. Cascade of function calls: ECHO opcode -&amp;gt; ZEND_ECHO_SPEC_CONST_HANDLER -&amp;gt;zend_print_variable()-&amp;gt;zend_print_zval-&amp;gt;zend_print_zval_ex-&amp;gt; False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false write_func() only display strings that are non-empty.
  61. Cascade of function calls: ECHO opcode -&amp;gt; ZEND_ECHO_SPEC_CONST_HANDLER -&amp;gt;zend_print_variable()-&amp;gt;zend_print_zval-&amp;gt;zend_print_zval_ex-&amp;gt; False in string context &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; == false Follows Perl – all unset vars have value of &amp;quot;&amp;quot; in string context; awkward to use &amp;quot;0&amp;quot; So, we see nothing b/c PHP prints empty string? No! PHP prints nothing in case of false write_func() only display strings that are non-empty.
  62. Is Father of PHP right? Manual explains allows conversion back and forth between boolean and string vals. (automatic and via casting). echo((bool)&amp;quot;&amp;quot;); can convert to false and then to &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; =&amp;gt; false nad then (string) false == &amp;quot;0&amp;quot; &amp;quot;&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;&amp;quot; &amp;quot;0&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;0&amp;quot; echo ( (bool) null);
  63. Is Father of PHP right? Manual explains allows conversion back and forth between boolean and string vals. (automatic and via casting). echo((bool)&amp;quot;&amp;quot;); can convert to false and then to &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; =&amp;gt; false nad then (string) false == &amp;quot;0&amp;quot; &amp;quot;&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;&amp;quot; &amp;quot;0&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;0&amp;quot; echo ( (bool) null);
  64. Is Father of PHP right? Manual explains allows conversion back and forth between boolean and string vals. (automatic and via casting). echo((bool)&amp;quot;&amp;quot;); can convert to false and then to &amp;quot;&amp;quot; but &amp;quot;0&amp;quot; =&amp;gt; false nad then (string) false == &amp;quot;0&amp;quot; &amp;quot;&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;&amp;quot; &amp;quot;0&amp;quot; =&amp;gt; false =&amp;gt; &amp;quot;0&amp;quot; echo ( (bool) null);
  65. Mirky issues …
  66. Null expr statement in for loop defaults to true in C, PHP. Per PHP3.0b4: Lang-syntax.sgml: &amp;quot;PHP&amp;apos;s syntax is borrowed primarily from C. Java and Perl have also influenced the syntax. &amp;quot; language-const.sgml: &amp;quot;The truth value of expressions in PHP is calculated in a similar way to perl. Any numeric non-zero numeric value is TRUE, zero is FALSE. … &amp;quot; &amp;quot;FOR … behave like their C counterparts. … Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). &amp;quot;
  67. Null expr statement in for loop defaults to true in C, PHP. Per PHP3.0b4: Lang-syntax.sgml: &amp;quot;PHP&amp;apos;s syntax is borrowed primarily from C. Java and Perl have also influenced the syntax. &amp;quot; language-const.sgml: &amp;quot;The truth value of expressions in PHP is calculated in a similar way to perl. Any numeric non-zero numeric value is TRUE, zero is FALSE. … &amp;quot; &amp;quot;FOR … behave like their C counterparts. … Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). &amp;quot;
  68. Alphanumeric string and per PHP3 manual: &amp;apos;empty() considers &amp;quot;0&amp;quot; as non-empty, a value that for example may come from an HTML form.&amp;apos; (see http://php.net/manual/php3.php) PHP4: &amp;apos;0&amp;apos; == 0, so empty() is true! (see https://bugs.php.net/bug.php?id=2088); Remedy: use isset() instead of empty() if &amp;quot;0&amp;quot; is valid input But PHP manual 3-&amp;gt;4: most controversial change empty(&amp;quot;0&amp;quot;) true!
  69. Alphanumeric string and per PHP3 manual: &amp;apos;empty() considers &amp;quot;0&amp;quot; as non-empty, a value that for example may come from an HTML form.&amp;apos; (see http://php.net/manual/php3.php) PHP4: &amp;apos;0&amp;apos; == 0, so empty() is true! (see https://bugs.php.net/bug.php?id=2088); Remedy: use isset() instead of empty() if &amp;quot;0&amp;quot; is valid input But PHP manual 3-&amp;gt;4: most controversial change empty(&amp;quot;0&amp;quot;) true!
  70. Empty str in PHP really is empty b/c PHP strings don&amp;apos;t have to be null-terminated. &amp;quot;&amp;quot; == true follows Perl and C which view string with one character. But &amp;quot;0&amp;quot; has one character – special exception so PHP follows Perl and renders it as false
  71. http://codepad.org/oWltWsa1 (Python &amp;quot;0&amp;quot; alphanumeric string evals as true. PHP unlike C has more than one way to express false. PHP waffled on &amp;quot;0&amp;quot; Originally false Then true alphanumeric string Then false b/c of problems with automatic conversions JS seems to have it both ways
  72. http://stackoverflow.com/questions/7615214/in-javascript-why-is-0-equal-to-false-but-not-false-by-itself JS sees a non-empty string, ergo it&amp;apos;s true 2nd example: false converts -&amp;gt; 0 and boolean coercision and &amp;quot;0&amp;quot; -&amp;gt; 0 http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/
  73. Arg for: &amp;quot;0&amp;quot; is a string with one character, so true makes sense. Concerned about type conversion consistency with scalars, unable to make a round trip with &amp;quot;&amp;quot; =&amp;gt; 0 =&amp;gt; &amp;quot;0&amp;quot; when &amp;quot;0&amp;quot; as a boolean expr == true * The empty() statement was added, which provides an easy to use and a &amp;gt; reliable way to check if a variable is both set and &amp;apos;non-empty&amp;apos; (if &amp;gt; (!empty($var))). This provides the &amp;apos;standard&amp;apos; way of checking on &amp;gt; whether a &amp;gt; form element coming from GPC has been filled out by the user or not. from:http://marc.info/?l=php-internals&amp;m=90222483131960&amp;w=2 same day change b/c only one response and was neutral; willing to use empty():
  74. Arg for: &amp;quot;0&amp;quot; is a string with one character, so true makes sense. Concerned about type conversion consistency with scalars, unable to make a round trip with &amp;quot;&amp;quot; =&amp;gt; 0 =&amp;gt; &amp;quot;0&amp;quot; when &amp;quot;0&amp;quot; as a boolean expr == true * The empty() statement was added, which provides an easy to use and a &amp;gt; reliable way to check if a variable is both set and &amp;apos;non-empty&amp;apos; (if &amp;gt; (!empty($var))). This provides the &amp;apos;standard&amp;apos; way of checking on &amp;gt; whether a &amp;gt; form element coming from GPC has been filled out by the user or not. from:http://marc.info/?l=php-internals&amp;m=90222483131960&amp;w=2 same day change b/c only one response and was neutral; willing to use empty():
  75. Arg for: &amp;quot;0&amp;quot; is a string with one character, so true makes sense. Concerned about type conversion consistency with scalars, unable to make a round trip with &amp;quot;&amp;quot; =&amp;gt; 0 =&amp;gt; &amp;quot;0&amp;quot; when &amp;quot;0&amp;quot; as a boolean expr == true * The empty() statement was added, which provides an easy to use and a &amp;gt; reliable way to check if a variable is both set and &amp;apos;non-empty&amp;apos; (if &amp;gt; (!empty($var))). This provides the &amp;apos;standard&amp;apos; way of checking on &amp;gt; whether a &amp;gt; form element coming from GPC has been filled out by the user or not. from:http://marc.info/?l=php-internals&amp;m=90222483131960&amp;w=2 same day change b/c only one response and was neutral; willing to use empty():
  76. Arg for: &amp;quot;0&amp;quot; is a string with one character, so true makes sense. Concerned about type conversion consistency with scalars, unable to make a round trip with &amp;quot;&amp;quot; =&amp;gt; 0 =&amp;gt; &amp;quot;0&amp;quot; when &amp;quot;0&amp;quot; as a boolean expr == true * The empty() statement was added, which provides an easy to use and a &amp;gt; reliable way to check if a variable is both set and &amp;apos;non-empty&amp;apos; (if &amp;gt; (!empty($var))). This provides the &amp;apos;standard&amp;apos; way of checking on &amp;gt; whether a &amp;gt; form element coming from GPC has been filled out by the user or not. from:http://marc.info/?l=php-internals&amp;m=90222483131960&amp;w=2 same day change b/c only one response and was neutral; willing to use empty():
  77. Re empty: See http://phpsadness.com/sad/28; php5.5 can be used with expressions. Equivalent of a boolean NOT Today, i.e. PHP5.5+ Anyone can make this mistake; a core dev recently did and when I brought it to his attn, he corrected it publicly. Maybe s.thing to fix in PHP?
  78. &amp;quot;0.0&amp;quot; follows Perl: &amp;quot;0.0&amp;quot; # not &amp;quot;0&amp;quot; or &amp;quot;&amp;quot; so TRUE PHP manual 3-&amp;gt;4: controversial change empty(&amp;quot;0&amp;quot;) true! &amp;quot;0.0&amp;quot; s/b false too!?
  79. Assumption: $items contains something that is countable. Strategy: check to see if it&amp;apos;s empty / === false || === 0 || === NULL (faster) $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null 1 as in long integer value 1, or as in 1 value; not return true. Per manual returns the count and by default 1 for scalars. Some have suggested (see http://justinsomnia.org/2007/12/in-php-countfalse-returns-1/) that behind scences the variable gets cast as an array and then counted; untrue! // zval *array;
  80. Assumption: $items contains something that is countable. Strategy: check to see if it&amp;apos;s empty / === false || === 0 || === NULL (faster) $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null 1 as in long integer value 1, or as in 1 value; not return true. Per manual returns the count and by default 1 for scalars. Some have suggested (see http://justinsomnia.org/2007/12/in-php-countfalse-returns-1/) that behind scences the variable gets cast as an array and then counted; untrue! // zval *array;
  81. Assumption: $items contains something that is countable. Strategy: check to see if it&amp;apos;s empty / === false || === 0 || === NULL (faster) $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null 1 as in long integer value 1, or as in 1 value; not return true. Per manual returns the count and by default 1 for scalars. Some have suggested (see http://justinsomnia.org/2007/12/in-php-countfalse-returns-1/) that behind scences the variable gets cast as an array and then counted; untrue! // zval *array;
  82. Assumption: $items contains something that is countable. Strategy: check to see if it&amp;apos;s empty / === false || === 0 || === NULL (faster) $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null 1 as in long integer value 1, or as in 1 value; not return true. Per manual returns the count and by default 1 for scalars. Some have suggested (see http://justinsomnia.org/2007/12/in-php-countfalse-returns-1/) that behind scences the variable gets cast as an array and then counted; untrue! // zval *array;
  83. Null like a room w/o furniture b/c the furniture is non-existent!
  84. SQL&amp;apos;s NULL : refers to a state rather than a value vs SQL_NULL == 0 PHPNG: zval type_info = IS_NULL (1) PHP4: 5/2000 PHP project&amp;apos;s greatest strength is its willingness to change. That kind of flexibility has contributed to its longevity. zend_register_constant(): lowercased name stored in HashTable Booleans arrive: may 2000 per http://en.wikipedia.org/wiki/PHP
  85. Like True and False is a Zend_constant but its ZVAL value has a data member value (union) that is unset. Its type IS_NULL and is the only data with this type. Null means does not exist, i.e. an unset value but some people had a challenging time comprehending, so Zeev spells it out …
  86. This undocumented casting feature for NULL seems ludicrous in light of the foregoing. How do you cast an entity that is unset, bereft of any value to a value of another type?? Undocumented intetionally but why? Behind the scense: Assignment of 0 and changing type of NULL. Code does same thing today except cleaner looking; uses macro. Added case of IS_UNSET avoided getting undefined variable message
  87. This undocumented casting feature for NULL seems ludicrous in light of the foregoing. How do you cast an entity that is unset, bereft of any value to a value of another type?? Undocumented intetionally but why? Behind the scense: Assignment of 0 and changing type of NULL. Code does same thing today except cleaner looking; uses macro. Added case of IS_UNSET avoided getting undefined variable message
  88. This undocumented casting feature for NULL seems ludicrous in light of the foregoing. How do you cast an entity that is unset, bereft of any value to a value of another type?? Undocumented intetionally but why? Behind the scense: Assignment of 0 and changing type of NULL. Code does same thing today except cleaner looking; uses macro. Added case of IS_UNSET avoided getting undefined variable message
  89. Argument for RFC: is_defined() for PHP JavaScript has such a func – why not PHP? Copycat arg idiotic – PHP has been a copycat since its inception! isset alone unable to distinguish between what&amp;apos;s been actually set and unset
  90. validation callbacks Argument for RFC: is_defined() for PHP JavaScript has such a func – why not PHP? Copycat arg idiotic – PHP has been a copycat since its inception! isset alone unable to distinguish between what&amp;apos;s been actually set and unset
  91. validation callbacks Argument for RFC: is_defined() for PHP JavaScript has such a func – why not PHP? Copycat arg idiotic – PHP has been a copycat since its inception! isset alone unable to distinguish between what&amp;apos;s been actually set and unset
  92. validation callbacks Argument for RFC: is_defined() for PHP JavaScript has such a func – why not PHP? Copycat arg idiotic – PHP has been a copycat since its inception! isset alone unable to distinguish between what&amp;apos;s been actually set and unset
  93. validation callbacks Argument for RFC: is_defined() for PHP JavaScript has such a func – why not PHP? Copycat arg idiotic – PHP has been a copycat since its inception! isset alone unable to distinguish between what&amp;apos;s been actually set and unset
  94. $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null https://bugs.php.net/bug.php?id=46322 Eisberg&amp;apos;s solution works but may be slow (see http://brian.moonspot.net/null-isset-php) per Sjon.
  95. $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null https://bugs.php.net/bug.php?id=46322 Eisberg&amp;apos;s solution works but may be slow (see http://brian.moonspot.net/null-isset-php) per Sjon.
  96. $items // perhaps result of $_POST Count() default return value 1 with scalars unless var is null https://bugs.php.net/bug.php?id=46322 Eisberg&amp;apos;s solution works but may be slow (see http://brian.moonspot.net/null-isset-php) per Sjon.
  97. Tjerk Meesters: RFC 12/2013 &amp;quot;Under discussion&amp;quot; 2 options: A) true-&amp;gt;false, false-&amp;gt;true; no more ++null and not --null B) true, false and null: ++/-- long ints, ie false=&amp;gt;true and ++true==2;--true=&amp;gt;false and –false=-1;null ++/-- Both cases: seek to replace ++/-- for strings with functions for next major version just as Perl does. Johannes Schlueter – trouble incrementing var with false val Felt it makes it harder than necessary for users. Incrementing and decrementing 0 effect on booleans and can&amp;apos;t decrement NULL. Patch went no where -- NULL and ++/-- boolean: no change and no error message In contrast to JS (EcmaScript) Derick Rethans reports that Andi G and he had discussed this sit in 2004 and Andi felt best not to tamper with PHP&amp;apos;s design. Why??? Contacted (Andi and) Tjerk … and Jack filled me in with why complicated.
  98. Tjerk Meesters: RFC 12/2013 &amp;quot;Under discussion&amp;quot; 2 options: A) true-&amp;gt;false, false-&amp;gt;true; no more ++null and not --null B) true, false and null: ++/-- long ints, ie false=&amp;gt;true and ++true==2;--true=&amp;gt;false and –false=-1;null ++/-- Both cases: seek to replace ++/-- for strings with functions for next major version just as Perl does. Johannes Schlueter – trouble incrementing var with false val Felt it makes it harder than necessary for users. Incrementing and decrementing 0 effect on booleans and can&amp;apos;t decrement NULL. Patch went no where -- NULL and ++/-- boolean: no change and no error message In contrast to JS (EcmaScript) Derick Rethans reports that Andi G and he had discussed this sit in 2004 and Andi felt best not to tamper with PHP&amp;apos;s design. Why??? Contacted (Andi and) Tjerk … and Jack filled me in with why complicated.
  99. Tjerk Meesters: RFC 12/2013 &amp;quot;Under discussion&amp;quot; 2 options: A) true-&amp;gt;false, false-&amp;gt;true; no more ++null and not --null B) true, false and null: ++/-- long ints, ie false=&amp;gt;true and ++true==2;--true=&amp;gt;false and –false=-1;null ++/-- Both cases: seek to replace ++/-- for strings with functions for next major version just as Perl does. Johannes Schlueter – trouble incrementing var with false val Felt it makes it harder than necessary for users. Incrementing and decrementing 0 effect on booleans and can&amp;apos;t decrement NULL. Patch went no where -- NULL and ++/-- boolean: no change and no error message In contrast to JS (EcmaScript) Derick Rethans reports that Andi G and he had discussed this sit in 2004 and Andi felt best not to tamper with PHP&amp;apos;s design. Why??? Contacted (Andi and) Tjerk … and Jack filled me in with why complicated.
  100. Tjerk Meesters: RFC 12/2013 &amp;quot;Under discussion&amp;quot; 2 options: A) true-&amp;gt;false, false-&amp;gt;true; no more ++null and not --null B) true, false and null: ++/-- long ints, ie false=&amp;gt;true and ++true==2;--true=&amp;gt;false and –false=-1;null ++/-- Both cases: seek to replace ++/-- for strings with functions for next major version just as Perl does. Johannes Schlueter – trouble incrementing var with false val Felt it makes it harder than necessary for users. Incrementing and decrementing 0 effect on booleans and can&amp;apos;t decrement NULL. Patch went no where -- NULL and ++/-- boolean: no change and no error message In contrast to JS (EcmaScript) Derick Rethans reports that Andi G and he had discussed this sit in 2004 and Andi felt best not to tamper with PHP&amp;apos;s design. Why??? Contacted (Andi and) Tjerk … and Jack filled me in with why complicated.
  101. So, how can NULL compare w/Any non-string value or a string? NULL-&amp;gt;&amp;quot;&amp;quot; and lexical comparison. In SQL, a field set to NULL can only be compared with IS NULL or IS NOT NULL operators b/c if there isn&amp;apos;t a value how can it be compared with one? PHP says &amp;quot;Yes, you can by applying boolean logic … Formerly Manual&amp;apos;s language &amp;quot;Convert to bool&amp;quot; -- language still in Belgium PHP Manual According to manual null compared with a non-string convert both operands to boolean values 
  102. So, how can NULL compare w/Any non-string value or a string? NULL-&amp;gt;&amp;quot;&amp;quot; and lexical comparison. In SQL, a field set to NULL can only be compared with IS NULL or IS NOT NULL operators b/c if there isn&amp;apos;t a value how can it be compared with one? PHP says &amp;quot;Yes, you can by applying boolean logic … Formerly Manual&amp;apos;s language &amp;quot;Convert to bool&amp;quot; -- language still in Belgium PHP Manual According to manual null compared with a non-string convert both operands to boolean values 
  103. Only care about one of the generated opcodes, IS_SMALLER and operands null and -1; tilde zero is temp var to be echoed. VM gets constructed and has functions to handle the generated opcode.
  104. Zend_vm_execute.h Macro invokes fast_is_smaller_function which due to nature of operands in turn calls compare_function (no &amp;apos;:&amp;apos;, etc. in actual source code – this is my pseudo source code).
  105. Null converts to 0 with type IS_BOOL -1 converts to 1 with type IS_BOOL So far code corresponds to manual. Normalize_bool uses ternary with choices -1 or 0 only like strcmp; 1 can&amp;apos;t be choice still NULL can never be greater than anything Normalize_bool returns an appropriate integer
  106. Null converts to 0 with type IS_BOOL -1 converts to 1 with type IS_BOOL So far code corresponds to manual. Normalize_bool uses ternary with choices -1 or 0 only like strcmp; 1 can&amp;apos;t be choice still NULL can never be greater than anything Normalize_bool returns an appropriate integer
  107. After PHP5.2 no longer was each operand converted if the the first is null; only the second one is. (see http://lxr.php.net/xref/PHP_5_2/Zend/zend_operators.c#1434) The choices reflect the capacity of null, ie can be less than op2 or == op2
  108. Resulting -1 appropriate for is_smaller just the way it is in strcmp
  109. Equality …
  110. == is transitive in this case; rare for PHP How does null == 0?.
  111. Note: expr statement – can do in C and in PHP, too Again vm machine Opcode generated (user who asked AF the ? Was me!)
  112. Macro calls fast_equal_function which calls compare_function w/null and zero
  113. After PHP5.2 no longer was each operand converted if the first is null; only the second one is. Result of op2 being a truthy value is false so 0 returned as a long int in result
  114. Result of 0 read and it == 0, so equality! Null == 0 is true
  115. Concluding Thoughts … Next time someone criticizes PHP, ask them: How much do they know about PHP&amp;apos;s internal workings? How well do they know the history of the lang and how well do they understand the langs that impacted PHP&amp;apos;s design? You really should learn C if you don&amp;apos;t already know it and start taking a look at PHP&amp;apos;s sourcecode. Ask your local PHP Meetup to start a SIG so you can study the sourcecode with others Result: better communication and collaboration between Userland and the core contributors You may also contemplate becoming a volunteer for the project and making the codebase and/or documentation better!