summaryrefslogtreecommitdiff
path: root/README.UPDATING_TO_PHP6
blob: d3547f28928df5f091f9ba76bc3aa6dbc46d6470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
Updating your script to PHP6
============================

This document attempts to describe portions of PHP that changed or
disapeared in PHP6 and the best practices for upgrading existing
applications to support PHP6.

1. Language
	1.1 Functions and function aliases
	1.2 Register globals
	1.3 Magic quotes
	1.4 Register long arrays ($HTTP_*_VARS)
	1.5 ZE1 compatibility mode
	1.6 dl() function
	1.7 E_ALL and E_STRICT constants
	1.8 References
2. Unicode (see README.UNICODE-UPGRADES)
2. Extensions
2.1 GD


1.1 Functions and function aliases
    ------------------------------

<TODO: List all arguments order changes, aliases droped in php6...>
1.2 Register globals
    ---------------- 

For security reasons, register_globals has been removed from php6.
ini_get('register_globals') will always return false.

You can emulate its behavior with some minimum changes in your code.

*DISCLAIMER*
people should get a short-term solution if they are willing to run
an insecure app.

Here is an example to emulate the session related functions and
a snippet to register variables:

$_register_globals_order = strrev(ini_get("variables_order"));
$_register_globals_order_len = strlen($_register_globals_order);

for($_register_globals_i=0;$_register_globals_i<$_register_globals_order_len;$_register_globals_i++) {
	switch($_register_globals_order{$_register_globals_i}) {
		case "E":
			extract($_ENV, EXTR_REFS|EXTR_SKIP);
		break;

		case "G":
			extract($_GET, EXTR_REFS|EXTR_SKIP);
		break;

		case "P":
			extract($_POST, EXTR_REFS|EXTR_SKIP);
		break;

		case "C":
			extract($_COOKIE, EXTR_REFS|EXTR_SKIP);
		break;

		case "S":
			extract($_SERVER, EXTR_REFS|EXTR_SKIP);
		break;
	}
}
unset($_register_globals_order, $_register_globals_order_len, $_register_globals_i);

function session_register($mixed) {
	static $started;
	if(!isset($started) || session_id() === "") {
		session_start();
		$started = true;
	}

	$array = func_get_args();
	foreach($array as $mixed) {

		if(is_scalar($mixed)) {
			$_SESSION[$mixed] =& $GLOBALS[$mixed];
		}
		elseif(is_array($mixed)) {
			foreach($mixed as $name) {
				$ok = session_register($name);
				if(!$ok) {
					return false;
				}
			}
		}
		else {
			return false;
		}
	}
	return true;
}

function session_is_registered($name) {
	if(is_scalar($name)) {
		return isset($_SESSION[$name]);
	}
	return false;
}

function session_unregister($name) {
	if(isset($_SESSION[$name]) && is_scalar($name)) {
		unset($_SESSION[$name]);
		return true;
	}
	return false;
}

1.3 Magic quotes
    ------------

1.4 Register long arrays ($HTTP_*_VARS)
    -----------------------------------

register_long_arrays and the long versions of super globals had been removed.
PHP will emit E_CORE_ERROR during PHP startup if it would detect
register_long_arrays setting.

You can emulate long arrays by including the following file:

<?php
if (!ini_get('register_long_arrays')) {	
	$HTTP_POST_VARS =& $_POST;
	$HTTP_GET_VARS =& $_GET;
	$HTTP_COOKIE_VARS =& $_COOKIE;
	$HTTP_SERVER_VARS =& $_SERVER;
	$HTTP_ENV_VARS =& $_ENV;
	$HTTP_POST_FILES =& $_FILES;
}
?>

1.5 ZE1 compatibility mode
    ----------------------

ZE1 compatibility mode (PHP4 object model) was introduced to migrate from PHP4
to PHP5 in an easier way, but it never keeped 100% compatibility.
It is completly removed in PHP6, and there is no way to emulate it.
Applications should assume PHP5/PHP6 object model.

1.6 dl() function
    -------------

Now dl() function is supported only in CLI, CGI and EMBED SAPI.
There is no way to emulte it. You can just check if dl() is supported by SAPI:

<?php
if (!function_exists("dl")) {
	die("dl() function is required\n!");
}
?>
    
1.7 E_ALL and E_STRICT constants
    ----------------------------

Now E_ALL error reporting mask includes E_STRICT.
You can filter E_STRICT error messages using the following code:

<?php
error_reporting(error_reporting() & ~E_STRICT);
?>

1.8 References
    ----------

<TODO: Derick plans to clean the reference mess in php6>

2.1 GD

<TODO: gd2/ft2 only, functions droped>