Error CMS_VERSION in cmsmadesimple 1.1.3.1

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
User avatar
mesaverde
Forum Members
Forum Members
Posts: 15
Joined: Sat Apr 07, 2007 3:20 pm
Location: Colorado, USA

Error CMS_VERSION in cmsmadesimple 1.1.3.1

Post by mesaverde »

There is a small error in the adodb.inc.php file in the latest update, version 1.1.3.1. This file can be found in the /lib/adodb_lite directory. The error will generate a warning message at the top of your webpage.

The first line of code reads

Code: Select all

if(!isset($GLOBALS[CMS_VERSION])) die('Attempt to use ADODB from outside of CMS');
You will need to add quotes around CMS_VERSION so that the line now reads

Code: Select all

if(!isset($GLOBALS['CMS_VERSION'])) die('Attempt to use ADODB from outside of CMS');
Hope this helps.
Ned Nowotny
Forum Members
Forum Members
Posts: 32
Joined: Mon Jan 29, 2007 1:19 am

Re: Error CMS_VERSION in cmsmadesimple 1.1.3.1

Post by Ned Nowotny »

mesaverde wrote:

Code: Select all

if(!isset($GLOBALS['CMS_VERSION'])) die('Attempt to use ADODB from outside of CMS');
As also noted in Re: Warning in CMS 1.1.3.1, TinyMCE, this code should be:

Code: Select all

if(!array_key_exists('CMS_VERSION', $GLOBALS)) die('Attempt to use ADODB from outside of CMS');
Or:

Code: Select all

if(!in_array('CMS_VERSION', array_keys($GLOBALS)) die('Attempt to use ADODB from outside of CMS');
Bobonov

Re: Error CMS_VERSION in cmsmadesimple 1.1.3.1

Post by Bobonov »

Ned Nowotny

even if all the 3 solution works, only one is the best in performance terms.
the first proposal by mesaverde, which simply fix the wrong code, use only isset() which is a function that simply test if the variable is setted and is quite fast
the second proposal by you, even if array_key_exist should do a similar work as isset but array key oriented I do not think that has best performance.
the third proposal is absolutely the worst one, it create an array out of the key of the original one (which I think iterate on the whole array take the key and add it to a second array), then on this array you use in_array which iterate on all the array element

I do not want to start a flame, but simply point out that propose solutions which are only worst than the one already implemented does not help
Ned Nowotny
Forum Members
Forum Members
Posts: 32
Joined: Mon Jan 29, 2007 1:19 am

Re: Error CMS_VERSION in cmsmadesimple 1.1.3.1

Post by Ned Nowotny »

Bobonov wrote: even if all the 3 solution works, only one is the best in performance terms.
In fact, I agree with your performance concerns.  The third option is certainly the slowest for the reasons you state; however, the second option could be as efficient as "isset" or as inefficient as the combination of "array_keys" and "in_array" depending on the implementation.  However, these are the options for testing for the existence of an element in a PHP array (or object).  The third option is required for PHP 4.0.5 and earlier and the second option is supported in PHP 4.0.7 and later.  (In PHP 4.0.6, the "array_key_exisits" function was named "key_exists".)

The problem with "isset" is that it is not intended for testing for the existence of an array element.  That is why it will produce the following warning when error reporting is set to the highest level:
Sy wrote: This isn't an error as such, but it will cause a warning to be displayed if you have errors set at the appropriate level in PHP.

Line 104. of TinyMCE.module.php, reads:

if (!$this->wysiwygactive ) {if (!$this->wysiwygactive && isset($_SESSION["tiny_live_textareas"]) ) {

Change this to:

if (!$this->wysiwygactive && isset($_SESSION["tiny_live_textareas"]) ) {

I get the warning:

Notice: Undefined index: tiny_live_textareas in C:\eska\modules\TinyMCE\TinyMCE.module.php on line 104

I always have error reporting set to display absolutely everything, which is good practice for development.
The problem is that "isset" is the logical negation of  "is_null" (possibly applied to multiple arguments).  In fact, the original poster could have changed the line in question to:

Code: Select all

if(is_null($GLOBALS['CMS_VERSION'])) die('Attempt to use ADODB from outside of CMS');
Because "$GLOBALS['CMS_VERSION']" should never exist and be set to NULL, this test will work either way while still triggering a warning just before the call to "die" if the "CMS_VERSION" array key does not exist.  However, there is still a difference between "isset" and "array_key_exisits" that is important in general:
  • isset - returns TRUE if the "variable" has been set and the value is not NULL.  It returns FALSE if it has never been set, if it has been "unset" (which may not work the way you think it does if the variable is a global variable), or if the variable does exist and the value of the variable is NULL.
  • array_key_exists - returns TRUE is there exists an element in the array for that key whether the value is NULL or not.  It returns FALSE otherwise.
This may seem like a largely pedantic point and it may well be.  However, using "isset" in place of "array_key_exists" is a habit that may lead to bugs that are difficult to identify when array values can be set to NULL (or, more likely, uninitialized).  It is a problem more easily avoided by consistently using "array_key_exists" as intended.

For a truly pedantic experience that clearly illustrates the relationship between "isset" and "is_null" while implicitly demonstrating the potential problem with not using "array_key_exists", try the following:

Code: Select all

<__html>
  <head>
    <title>isset and is_null test</title>
  </head>
  </__body>
    <p>
      isset( $variable ): <?php var_dump( isset( $variable ) ); ?><br />
      is_null( $variable ): <?php var_dump( is_null( $variable ) ); ?><br />
    </p>
    <p>
      $variable = NULL;<?php $variable = NULL; ?><br /><br />
      isset( $variable ): <?php var_dump( isset( $variable ) ); ?><br />
      is_null( $variable ): <?php var_dump( is_null( $variable ) ); ?><br />
    </p>
    <p>
      $variable = 1;<?php $variable = 1; ?><br /><br />
      isset( $variable ): <?php var_dump( isset( $variable ) ); ?><br />
      is_null( $variable ): <?php var_dump( is_null( $variable ) ); ?><br />
    </p>
    <p>
      unset( $variable );<?php unset( $variable ); ?><br /><br />
      isset( $variable ): <?php var_dump( isset( $variable ) ); ?><br />
      is_null( $variable ): <?php var_dump( is_null( $variable ) ); ?><br />
    </p>
    <p>
      isset( $arr ): <?php var_dump( isset( $arr ) ); ?><br />
      is_null( $arr ): <?php var_dump( is_null( $arr ) ); ?><br />
    </p>
    <p>
      $arr = array();<?php $arr = array(); ?><br /><br />
      isset( $arr ): <?php var_dump( isset( $arr ) ); ?><br />
      is_null( $arr ): <?php var_dump( is_null( $arr ) ); ?><br />
    </p>
    <p>
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      $arr['foo'];<?php $arr['foo']; ?><br /><br />
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      $arr['foo'] = NULL;<?php $arr['foo'] = NULL; ?><br /><br />
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      $arr['foo'] = 1;<?php $arr['foo'] = 1; ?><br /><br />
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      unset( $arr['foo'] );<?php unset( $arr['foo'] ); ?><br /><br />
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      unset( $arr );<?php unset( $arr ); ?><br /><br />
      isset( $arr['foo'] ): <?php var_dump( isset( $arr['foo'] ) ); ?><br />
      is_null( $arr['foo'] ): <?php var_dump( is_null( $arr['foo'] ) ); ?><br />
    </p>
    <p>
      isset( $arr ): <?php var_dump( isset( $arr ) ); ?><br />
      is_null( $arr ): <?php var_dump( is_null( $arr ) ); ?><br />
    </p>
  <__body>
</__html>
Locked

Return to “CMSMS Core”