php-5.3

How to detect if a user uploaded a file larger than post_max_size?

元气小坏坏 提交于 2019-11-28 00:58:10
How should I go about handling http uploads that exceeds the post_max_size in a sane manner? In my configuration post_max_size is a few MB larger than upload_max_filesize The problems I'm having are: If a user uploads a file exceeding post_max_size The _POST array is empty The _FILES array is empty, and of course any error codes therein are not present. No other info what kind of form post it is is accessible through theses means. Part of the problem is that the receiving script takes different actions depending on the contents of the POST. I do have access to the _SERVER variables and can get

Why do strings behave like an array in PHP 5.3?

谁说我不能喝 提交于 2019-11-27 23:14:52
问题 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? 回答1: 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 |

PHP is handling incorrectly my static call

和自甴很熟 提交于 2019-11-27 19:02:59
问题 I'm havinh a problem on PHP 5.3. I need to call a method by using __callStatic , but if I use it in a instancied object, PHP call __call instead. Above a real life example: <?php class A { function __call($method, $args){ // Note: $this is defined! echo "Ops! Don't works. {$this->c}"; } static function __callStatic($method, $args){ echo 'Fine!'; } } class B extends A { public $c = 'Real Ops!'; function useCallStatic(){ static::foo(); // === A::foo(); // === B::foo(); } } $foo = new B(); $foo-

About PHP underscore naming convention (as in “_method” or “_property”)

浪子不回头ぞ 提交于 2019-11-27 17:21:13
问题 This is a sort of general inquiry I've been wondering about. I've noticed a lot of this through other people's code, and never really knew the actual reason, just followed the trends, so here goes. How come some methods and properties are named with an underscore in front, and others aren't? For example, when specifically would one use function _method() , and when would one use function method() , or, in other words, private $_someVariable vs. private $someVariable ? 回答1: Most of the time,

PHP 5.3: Late static binding doesn't work for properties when defined in parent class while missing in child class

心已入冬 提交于 2019-11-27 16:21:54
问题 Take a look at this example, and notice the outputs indicated. <?php class Mommy { protected static $_data = "Mommy Data"; public static function init( $data ) { static::$_data = $data; } public static function showData() { echo static::$_data . "<br>"; } } class Brother extends Mommy { } class Sister extends Mommy { } Brother::init( "Brother Data" ); Sister::init( "Sister Data" ); Brother::showData(); // Outputs: Sister Data Sister::showData(); // Outputs: Sister Data ?> My understanding was

PHP DOM: parsing a HTML list into an array?

醉酒当歌 提交于 2019-11-27 15:19:03
问题 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

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

ε祈祈猫儿з 提交于 2019-11-27 07:00:45
问题 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

Write to file with register_shutdown_function

 ̄綄美尐妖づ 提交于 2019-11-27 06:41:28
问题 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. 回答1: 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 (

How to configure Codeigniter to report all errors?

China☆狼群 提交于 2019-11-27 06:40:34
问题 I had a line - $autoload['libraries'] = array('database'); , in CI's autoload.php . Because of this I was getting a blank page. When I removed the 'database' , option then I started getting the output. Now my question is not how to configure the database, but how to configure CI to speak its mind. When 'database' was enabled all I got was a complete blank page. No error in php log, no error in Apache log, no error in CI log. In PHP I have set E_ALL . In my CI config I have set log_threshold

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

爷,独闯天下 提交于 2019-11-27 05:51:23
问题 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