From 1228fe27bc1f22838cd80c5fe33c37274faf0e24 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 14 Jan 2013 01:30:09 +0100 Subject: Replace is_null() with === / !== NULL Exact same behavior, but faster. I also think it's more readable. --- system/core/Loader.php | 8 ++++---- system/database/DB_driver.php | 2 +- system/database/DB_query_builder.php | 18 +++++++++--------- system/database/DB_result.php | 2 +- system/libraries/Email.php | 2 +- system/libraries/Form_validation.php | 6 +++--- system/libraries/Ftp.php | 4 ++-- system/libraries/Javascript.php | 4 ++-- system/libraries/Table.php | 2 +- system/libraries/Unit_test.php | 4 ++-- system/libraries/User_agent.php | 2 +- system/libraries/Xmlrpc.php | 2 +- 12 files changed, 28 insertions(+), 28 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index 4d95d6288..1ad07f1fa 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -205,7 +205,7 @@ class CI_Loader { return; } - if ( ! is_null($params) && ! is_array($params)) + if ($params !== NULL && ! is_array($params)) { $params = NULL; } @@ -975,7 +975,7 @@ class CI_Loader { // Before we deem this to be a duplicate request, let's see // if a custom object name is being supplied. If so, we'll // return a new instance of the object - if ( ! is_null($object_name)) + if ($object_name !== NULL) { $CI =& get_instance(); if ( ! isset($CI->$object_name)) @@ -1014,7 +1014,7 @@ class CI_Loader { // Before we deem this to be a duplicate request, let's see // if a custom object name is being supplied. If so, we'll // return a new instance of the object - if ( ! is_null($object_name)) + if ($object_name !== NULL) { $CI =& get_instance(); if ( ! isset($CI->$object_name)) @@ -1144,7 +1144,7 @@ class CI_Loader { // Was a custom class name supplied? If so we'll use it $class = strtolower($class); - if (is_null($object_name)) + if ($object_name === NULL) { $classvar = isset($this->_ci_varmap[$class]) ? $this->_ci_varmap[$class] : $class; } diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 1e5e8c6f7..26791398a 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -993,7 +993,7 @@ abstract class CI_DB_driver { { return ($str === FALSE) ? 0 : 1; } - elseif (is_null($str)) + elseif ($str === NULL) { return 'NULL'; } diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index dc2c5e702..978fc6af7 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -644,7 +644,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { ? $this->_group_get_type('') : $this->_group_get_type($type); - if ( ! is_null($v)) + if ($v !== NULL) { if ($escape === TRUE) { @@ -1202,7 +1202,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function limit($value, $offset = FALSE) { - is_null($value) OR $this->qb_limit = (int) $value; + $value === NULL OR $this->qb_limit = (int) $value; empty($offset) OR $this->qb_offset = (int) $offset; return $this; @@ -1382,7 +1382,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->from($table); } - if ( ! is_null($where)) + if ($where !== NULL) { $this->where($where); } @@ -1411,7 +1411,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function insert_batch($table = '', $set = NULL, $escape = NULL) { - if ( ! is_null($set)) + if ($set !== NULL) { $this->set_insert_batch($set, '', $escape); } @@ -1567,7 +1567,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function insert($table = '', $set = NULL, $escape = NULL) { - if ( ! is_null($set)) + if ($set !== NULL) { $this->set($set, '', $escape); } @@ -1633,7 +1633,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function replace($table = '', $set = NULL) { - if ( ! is_null($set)) + if ($set !== NULL) { $this->set($set); } @@ -1742,7 +1742,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // Combine any cached components with the current statements $this->_merge_cache(); - if ( ! is_null($set)) + if ($set !== NULL) { $this->set($set); } @@ -1815,12 +1815,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // Combine any cached components with the current statements $this->_merge_cache(); - if (is_null($index)) + if ($index === NULL) { return ($this->db_debug) ? $this->display_error('db_must_use_index') : FALSE; } - if ( ! is_null($set)) + if ($set !== NULL) { $this->set_update_batch($set, $index); } diff --git a/system/database/DB_result.php b/system/database/DB_result.php index dfd8081fd..a044fd5dc 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -354,7 +354,7 @@ class CI_DB_result { return; } - if ($key !== '' && ! is_null($value)) + if ($key !== '' && $value !== NULL) { $this->row_data[$key] = $value; } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1834be239..3a386456d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1335,7 +1335,7 @@ class CI_Email { for ($i = 0, $c = count($this->_attachments), $z = 0; $i < $c; $i++) { $filename = $this->_attachments[$i]['name'][0]; - $basename = is_null($this->_attachments[$i]['name'][1]) + $basename = $this->_attachments[$i]['name'][1] === NULL ? basename($filename) : $this->_attachments[$i]['name'][1]; $ctype = $this->_attachments[$i]['type']; $file_content = ''; diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index c405eb6b1..bbd0b523e 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -511,7 +511,7 @@ class CI_Form_validation { { foreach ($this->_field_data as $field => $row) { - if ( ! is_null($row['postdata'])) + if ($row['postdata'] !== NULL) { if ($row['is_array'] === FALSE) { @@ -583,7 +583,7 @@ class CI_Form_validation { // If the field is blank, but NOT required, no further tests are necessary $callback = FALSE; - if ( ! in_array('required', $rules) && is_null($postdata)) + if ( ! in_array('required', $rules) && $postdata === NULL) { // Before we bail out, does the rule contain a callback? if (preg_match('/(callback_\w+(\[.*?\])?)/', implode(' ', $rules), $match)) @@ -598,7 +598,7 @@ class CI_Form_validation { } // Isset Test. Typically this rule will only apply to checkboxes. - if (is_null($postdata) && $callback === FALSE) + if ($postdata === NULL && $callback === FALSE) { if (in_array('isset', $rules, TRUE) OR in_array('required', $rules)) { diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index b8729a9c7..dc6bbd226 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -266,7 +266,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if ($permissions !== NULL) { $this->chmod($path, (int) $permissions); } @@ -320,7 +320,7 @@ class CI_FTP { } // Set file permissions if needed - if ( ! is_null($permissions)) + if ($permissions !== NULL) { $this->chmod($rempath, (int) $permissions); } diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 542a0ecde..7f1d85511 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -737,7 +737,7 @@ class CI_Javascript { { // JSON data can optionally be passed to this function // either as a database result object or an array, or a user supplied array - if ( ! is_null($result)) + if ($result !== NULL) { if (is_object($result)) { @@ -823,7 +823,7 @@ class CI_Javascript { */ protected function _prep_args($result, $is_key = FALSE) { - if (is_null($result)) + if ($result === NULL) { return 'null'; } diff --git a/system/libraries/Table.php b/system/libraries/Table.php index 865699052..b77fcf19d 100644 --- a/system/libraries/Table.php +++ b/system/libraries/Table.php @@ -291,7 +291,7 @@ class CI_Table { { // The table data can optionally be passed to this function // either as a database result object or an array - if ( ! is_null($table_data)) + if ($table_data !== NULL) { if (is_object($table_data)) { diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index de8c9bb80..7a67c7276 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -356,12 +356,12 @@ class CI_Unit_test { */ protected function _parse_template() { - if ( ! is_null($this->_template_rows)) + if ($this->_template_rows !== NULL) { return; } - if (is_null($this->_template) OR ! preg_match('/\{rows\}(.*?)\{\/rows\}/si', $this->_template, $match)) + if ($this->_template === NULL OR ! preg_match('/\{rows\}(.*?)\{\/rows\}/si', $this->_template, $match)) { $this->_default_template(); return; diff --git a/system/libraries/User_agent.php b/system/libraries/User_agent.php index 542deb738..1f4b2fa52 100644 --- a/system/libraries/User_agent.php +++ b/system/libraries/User_agent.php @@ -158,7 +158,7 @@ class CI_User_agent { $this->agent = trim($_SERVER['HTTP_USER_AGENT']); } - if ( ! is_null($this->agent) && $this->_load_agent_file()) + if ($this->agent !== NULL && $this->_load_agent_file()) { $this->_compile_data(); } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index c3c7690f0..9e60791ae 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -368,7 +368,7 @@ class CI_Xmlrpc { */ public function timeout($seconds = 5) { - if ( ! is_null($this->client) && is_int($seconds)) + if ($this->client !== NULL && is_int($seconds)) { $this->client->timeout = $seconds; } -- cgit v1.2.3-24-g4f1b From 5b60a3bb74d39b8718081cb62c21f9f48e7a4a87 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 15 Jan 2013 04:19:03 +0200 Subject: [ci skip] Fix issue #2157 - docs on the email library --- user_guide_src/source/libraries/email.rst | 52 +++++++++++++++++-------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index 8643444f8..7d468251c 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -40,8 +40,6 @@ This example assumes you are sending the email from one of your $this->email->send(); - echo $this->email->print_debugger(); - Setting Email Preferences ========================= @@ -51,7 +49,7 @@ or automatically via preferences stored in your config file, described below: Preferences are set by passing an array of preference values to the -email initialize function. Here is an example of how you might set some +email initialize method. Here is an example of how you might set some preferences:: $config['protocol'] = 'sendmail'; @@ -71,8 +69,8 @@ If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to -use the $this->email->initialize() function if you save your preferences -in a config file. +use the ``$this->email->initialize()`` method if you save your +preferences in a config file. Email Preferences ================= @@ -107,8 +105,8 @@ Preference Default Value Options Descript **dsn** FALSE TRUE or FALSE (boolean) Enable notify message from server =================== ====================== ============================ ======================================================================= -Email Function Reference -======================== +Email Methods Reference +======================= $this->email->from() -------------------- @@ -125,10 +123,10 @@ You can also set a Return-Path, to help redirect undelivered mail:: 'smtp' as your protocol. $this->email->reply_to() -------------------------- +------------------------ Sets the reply-to address. If the information is not provided the -information in the "from" function is used. Example:: +information in the "from" method is used. Example:: $this->email->reply_to('you@example.com', 'Your Name'); @@ -177,7 +175,7 @@ Sets the email message body:: $this->email->message('This is my message'); $this->email->set_alt_message() ---------------------------------- +------------------------------- Sets the alternative email message body:: @@ -200,21 +198,21 @@ Appends additional headers to the e-mail:: $this->email->clear() --------------------- -Initializes all the email variables to an empty state. This function is -intended for use if you run the email sending function in a loop, +Initializes all the email variables to an empty state. This method is +intended for use if you run the email sending method in a loop, permitting the data to be reset between cycles. :: foreach ($list as $name => $address) { - $this->email->clear(); + $this->email->clear(); - $this->email->to($address); - $this->email->from('your@example.com'); - $this->email->subject('Here is your info '.$name); - $this->email->message('Hi '.$name.' Here is the info you requested.'); - $this->email->send(); + $this->email->to($address); + $this->email->from('your@example.com'); + $this->email->subject('Here is your info '.$name); + $this->email->message('Hi '.$name.' Here is the info you requested.'); + $this->email->send(); } If you set the parameter to TRUE any attachments will be cleared as @@ -225,15 +223,15 @@ well:: $this->email->send() -------------------- -The Email sending function. Returns boolean TRUE or FALSE based on +The Email sending method. Returns boolean TRUE or FALSE based on success or failure, enabling it to be used conditionally:: if ( ! $this->email->send()) { - // Generate error + // Generate error } -This function will automatically clear all parameters if the request was +This method will automatically clear all parameters if the request was successful. To stop this behaviour pass FALSE:: if ($this->email->send(FALSE)) @@ -241,12 +239,15 @@ successful. To stop this behaviour pass FALSE:: // Parameters won't be cleared } +.. note:: In order to use the ``print_debugger()`` method, you need + to avoid clearing the email parameters. + $this->email->attach() ---------------------- Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. For multiple attachments -use the function multiple times. For example:: +use the method multiple times. For example:: $this->email->attach('/path/to/photo1.jpg'); $this->email->attach('/path/to/photo2.jpg'); @@ -278,6 +279,11 @@ Valid options are: **headers**, **subject**, **body**. Example:: + // You need to pass FALSE while sending in order for the email data + // to not be cleared - if that happens, print_debugger() would have + // nothing to output. + $this->email->send(FALSE); + // Will only print the email headers, excluding the message subject and body $this->email->print_debugger(array('headers')); @@ -301,4 +307,4 @@ message like this:: wrapped normally. -Place the item you do not want word-wrapped between: {unwrap} {/unwrap} +Place the item you do not want word-wrapped between: {unwrap} {/unwrap} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 912f1bcbc3d4f9b09695ab784d6985efbc4c9235 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 15 Jan 2013 03:34:12 +0100 Subject: A few adjustments to previous commit --- system/database/DB_query_builder.php | 2 +- system/libraries/Email.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 978fc6af7..ac377d996 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1202,7 +1202,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function limit($value, $offset = FALSE) { - $value === NULL OR $this->qb_limit = (int) $value; + is_null($value) OR $this->qb_limit = (int) $value; empty($offset) OR $this->qb_offset = (int) $offset; return $this; diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 3a386456d..997757b0a 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1335,7 +1335,7 @@ class CI_Email { for ($i = 0, $c = count($this->_attachments), $z = 0; $i < $c; $i++) { $filename = $this->_attachments[$i]['name'][0]; - $basename = $this->_attachments[$i]['name'][1] === NULL + $basename = ($this->_attachments[$i]['name'][1] === NULL) ? basename($filename) : $this->_attachments[$i]['name'][1]; $ctype = $this->_attachments[$i]['type']; $file_content = ''; -- cgit v1.2.3-24-g4f1b