php-5.3

Is it possible to change the Wordpress parameter “/page/2” to something else?

依然范特西╮ 提交于 2020-06-13 08:01:48
问题 Disclaimer : I'm working on a legacy corporate WP site (PHP 5.3.3), and I can't make very many major breaking changes. I am adding pagination to an existing resources page (/resources). I'm fairly new to Wordpress in general, but I do have my page working and displaying the correct number of resources on page load. My question is: when you paginate in Wordpress using: <?php next_posts_link( 'More Resources' , $the_query->max_num_pages ); ?> It creates a link on the page, and when you click it

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说我不能喝 提交于 2020-06-08 16:52:44
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

How do I test for an exact Exception message, rather than a substring, with PHPUnit?

谁说胖子不能爱 提交于 2020-06-08 16:51:42
问题 According to the PHPUnit Documentation on @expectedExceptionMessage , the string must only be a substring of the actual Exception thrown. In one of my validation methods, an array item is pushed for each error that occurs, and the final Exception message is displayed by imploding the array of errors. class MyClass { public function validate($a, $b, $c, $d) { if($a < $b) $errors[] = "a < b."; if($b < $c) $errors[] = "b < c."; if($c < $d) $errors[] = "c < d."; if(count($errors) > 0) throw new

Set the HTTP content type response to “application/json” in php

偶尔善良 提交于 2020-02-08 02:25:08
问题 I have a question. I have the folowing condition : You should return an HTTP 500 status code and more details about the error in the message body. Set the HTTP content type response to “application/json”.The error detail must be in JSON format as described below: { "ErrorCode" : 402, "ErrorMessage" : "Item" } I tried like this : if(!Gain::verifyIfUserExistByIdm($aOutput['UserId'])){ header("HTTP/1.0 500 Internal Server Error"); return json_encode(array('ErrorCode'=>407,'ErrorMessage'=>'Error'

Notice: Undefined property - how do I avoid that message in PHP?

五迷三道 提交于 2020-02-01 23:38:27
问题 Hello I am making this call: $parts = $structure->parts; Now $structure only has parts under special circumstances, so the call returns me null. Thats fine with me, I have a if($parts) {...} later in my code. Unfortunately after the code finished running, I get this message: Notice: Undefined property: stdClass::$parts in ... How can I suppress this message? Thanks! 回答1: The function isset should do exactly what you need. PHP: isset - Manual Example: $parts = (isset($structure->parts) ?

PHP forward_static_call vs call_user_func

陌路散爱 提交于 2020-01-22 10:40:11
问题 What is the difference between forward_static_call and call_user_func And the same question applies to forward_static_call_array and call_user_func_array 回答1: The difference is just that forward_static_call does not reset the "called class" information if going up the class hierarchy and explicitly naming a class, whereas call_user_func resets the information in those circumstances (but still does not reset it if using parent , static or self ). Example: <?php class A { static function bar()

Why don't php deprecated features (as opposed to deprecated functions) call the error_handler function?

前提是你 提交于 2020-01-16 04:40:07
问题 I am upgrading a codebase from php 5.2 to 5.3. As part of this I am converting our uses of deprecated functions and features. When we use deprecated functions like split and spliti the error handler that we setup by calling set_error_handler() is called and I get a log message. This is great. But, when I use the following two deprecated features: Assigning the return value of new by reference is now deprecated. Call-time pass-by-reference is now deprecated. The error handler is not called so

Insert data from datepicker in database using php

邮差的信 提交于 2020-01-15 23:58:53
问题 I have a problem and I can't resolve it, So my script: <script> $(document).ready(function() { $("#datepicker").datepicker({ format: 'dd-mm-yy' }); }) My html: <div class="form-group"> <label>Date:</label> <input class="form-control marg-left-10" name="date" type="text" id="datepicker"> </div> My php: $date = date('dd-mm-yy', strtotime($this->input->post['date'])); But the date doesn't insert, in my database the date look like this : 0000-00-00 Help me please 回答1: Use the appropriate format /

array_diff on array of associative arrays in php

↘锁芯ラ 提交于 2020-01-15 15:59:12
问题 I have two arrays of the form Array1: [0]=> Array([name] => foo [id] => 12) [1]=> Array([name] => bar [id] => 34) Array2: [0]=>Array([name] => bar [id]=> 34) [1]=>Array([name] => baz [id]=> 56) The arrays come from a database and any two pairs can have the same name but ID's are unique. I am trying to compare the arrays by ID likes so: $one_not_two = array_diff($array1[id], $array2[id]); but that does not return anything. I also tried $one_not_two = array_diff($array1[id], $array2[id]); which

DDD: is it ok to inject a Service into an Entity

吃可爱长大的小学妹 提交于 2020-01-13 03:20:08
问题 I have a tree of Zone objects: class Zone { protected $parent; public function __construct(Zone $parent) { $this->parent = $parent; } } There are no children nor descendants property in the Zone, because I want to avoid the pain of managing these relationships in the domain model. Instead, a domain service maintains a closure table in the database, to map a zone to all its descendants, at any level. Now, I have a User which can be assigned one or more Zones: class User { protected $zones;