php-5.3

Non-deterministic object reference bug in PHP 5.3.X

↘锁芯ラ 提交于 2019-11-29 07:38:58
As of yesterday (perhaps after a recent PHP update?), I'm getting some very strange non-deterministic bugs in php 5.3.3. These appear in our production server in PHP 5.3.2 as well. The errors essentially amount to Fatal error: Uncaught exception 'ErrorException' with message 'Attempt to assign property of non-object' in various parts of the code base. Generally, the error line is something like: $this->foo = $bar in a __construct() call. $this is not found in the constructor?! I have no idea what is going on. Any ideas? Is this possibly a regression of this bug?: http://bugs.php.net/31525 Edit

Why do strings behave like an array in PHP 5.3?

馋奶兔 提交于 2019-11-29 05:39:09
I have this code: $tierHosts['host'] = isset($host['name']) ? $host['name'] : $host; It's working fine in PHP 5.5, but in PHP 5.3 the condition returns true while $host contains a string like pjba01 . It returns the first letter of $tierHosts['host'] , that is, p . What's so wrong with my code? You can access strings like an array and prior PHP 5.4 offsets like your name were silently casted to 0, means you accessed the first character of that string: character | p | j | b | a | 0 | 1 | ----------------------------------- index | 0 | 1 | 2 | 3 | 4 | 5 | After 5.3 such offsets will throw a

PHP DOM: parsing a HTML list into an array?

北城以北 提交于 2019-11-29 00:18:27
I have the below HTML string, and I would like to turn it into an array. $string = ' <a href="#" class="something">1</a> <a href="#" class="something">2</a> <a href="#" class="something">3</a> <a href="#" class="something">4</a> '; Here's my current code with DOMDocument : $dom = new DOMDocument; $dom->loadHTML($string); foreach( $dom->getElementsByTagName('a') as $node) { $array[] = $node->nodeValue; } print_r($array); However, this gives the below output: Array ( [0] => 1 [1] => 2 [2] => 2 [3] => 4) But I am looking for this result: Array ( [0] => <a href="#" class="something">1</a> [1] =>

Why does PHP overwrite values when I iterate through this array twice (by reference, by value)

最后都变了- 提交于 2019-11-28 12:30:33
If I iterate through an array twice, once by reference and then by value, PHP will overwrite the last value in the array if I use the same variable name for each loop. This is best illustrated through an example: $array = range(1,5); foreach($array as &$element) { $element *= 2; } print_r($array); foreach($array as $element) { } print_r($array); Output: Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 [4] => 10 ) Array ( [0] => 2 [1] => 4 [2] => 6 [3] => 8 [4] => 8 ) Note that I am not looking for a fix, I am looking to understand why this is happening. Also note that it does not happen if the

Write to file with register_shutdown_function

会有一股神秘感。 提交于 2019-11-28 12:01:37
Is it possible to do the following? register_shutdown_function('my_shutdown'); function my_shutdown () { file_put_contents('test.txt', 'hello', FILE_APPEND); error_log('hello', 3, 'test.txt'); } Doesn't seem to work. BTW i'm on PHP 5.3.5. It depends which SAPI you are using. The documentation page for register_shutdown_function() states that under certain servers, like Apache, the working directory of the script changes. The file gets written, but not where your .php file is ( DocumentRoot ), but in the folder of the Apache server ( ServerRoot ). To prevent this, you need to some sort of

Warning: preg_match() [function.preg-match]: Unknown modifier '-' [duplicate]

和自甴很熟 提交于 2019-11-28 11:15:15
问题 This question already has answers here : Warning: preg_replace(): Unknown modifier ']' (3 answers) Closed 5 months ago . I change ereg to preg_match for update mycode to PHP5.3 . now i see this warning in my page. how to fix this ? warning : Warning: preg_match() [function.preg-match]: Unknown modifier '-' in C:\xampp\htdocs\share\configs\functions.php on line 2645 old Code : if (!ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $dateOfBirth, $regs)) New Code (PHP 5.3): if (!preg_match ("([0-9]

Parse error: syntax error, unexpected '[' with php 5.3 [duplicate]

邮差的信 提交于 2019-11-28 09:44:30
This question already has an answer here: PHP syntax for dereferencing function result 22 answers My script is working really fine on my xampp. Now I tried to upload it on the server, but it spat directly a Parse error: syntax error, unexpected '[' in my face. :( The line which its mocking about is this one: $item = $xml->xpath($path)[0]; And I have no idea what is wrong. I tried to look on the php 5.3 changelog but did not found anything about it. (Because I have 5.3 on the server, and on xampp its an olderversion) The whole code block looks like this: $path = '//item[@id="'.$id.'"]'; if (

How to connect to MSSQL 2000 from PHP 5.3 and up

孤街浪徒 提交于 2019-11-28 09:29:08
I have a legacy business application built on MS SQL Server 2000. I have some webbased utilities that access this database using PHP 5.2 with mssql extension. I need to reinstall the web server, and I looked forward to upgrade to PHP 5.4. Unfortunately, the mssql extension is not supported on PHP 5.3 and newer. There is the sqlsrv extension available form Microsoft , but the description says that it is only supported for accessing SQL server 2005 and up. How can I connect to my SQL Server 2000 from PHP 5.4 ? Did anyone already solve this issue ? This is a really complicated issue. Here are the

mssql_connect no longer working as of PHP 5.3

二次信任 提交于 2019-11-28 08:46:50
问题 I just received an email from our host and they've upgraded our PHP to 5.3, unfortunately though, all the scripts have now broken. I traced it down to the function mssql_connect failing. Support told me this has now been deprecated under 5.3 - how can this be true? How can you connect to a mssql database under PHP 5.3 now?? 回答1: http://www.php.net/manual/en/intro.mssql.php "This extension is not available anymore on Windows with PHP 5.3 or later." Maybe you should look into converting your

curl posting with header application/x-www-form-urlencoded

て烟熏妆下的殇ゞ 提交于 2019-11-28 06:48:22
$post_data="dispnumber=567567567&extension=6"; $url="http://xxxxxxxx.xxx/xx/xx"; I need to post this $post_data using cURL php with header application/x-www-form-urlencoded i am new for curl any one help this out. <?php // // A very simple PHP example that sends a HTTP POST to a remote site // $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"http://xxxxxxxx.xxx/xx/xx"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "dispnumber=567567567&extension=6"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); // receive server