When using this module, I've experienced a number of PHP warning messages in admin/reports/dblog.

Notice: Use of undefined constant PHP_MAJOR_VERSION - assumed 'PHP_MAJOR_VERSION' in _views_json_json_encode() (line 354 of /.../sites/all/modules/views_datasource/views_json.module).

Any help? Thank you.

CommentFileSizeAuthor
#3 views_datasource-1786056-3.patch1.3 KBcs_shadow

Comments

Ivo.Radulovski’s picture

Issue summary: View changes

got the same error

pasqualle’s picture

http://php.net/manual/en/reserved.constants.php#reserved.constants.core
PHP_MAJOR_VERSION Available since PHP 5.2.7
PHP_MINOR_VERSION Available since PHP 5.2.7

https://drupal.org/requirements
Drupal 7: PHP 5.2.5 or higher

before using the php constant there should be a check
if (defined('PHP_MAJOR_VERSION'))

cs_shadow’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

Attached is a patch that should fix this warning. Here, I check whether or not PHP_MAJOR_VERSION is defined. If its not, we can definitely conclude that PHP version < 5.4

turek’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

turek’s picture

Well actually it only worked as I used that path while using PHP 5.3.x but when tested on PHP 5.2.6 it produces another warning, because it falls back into the first if statement and uses json_encode with 2 parameters - which produces notice on PHP version lower than 5.2.7.

-  if(PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
+  if(!defined('PHP_MAJOR_VERSION') || !PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
     $json = json_encode($rows, $bitmask);
     // Encoding features not supported before 5.4.x.
     if(PHP_MINOR_VERSION <= 4) {

That should be changed to this:

if(defined('PHP_MAJOR_VERSION') && !PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
turek’s picture

Status: Reviewed & tested by the community » Needs work

  • japerry committed 3a57ce4 on 7.x-1.x
    Issue #1786056 by japerry, cs_shadow, Turek: Notice: Use of undefined...
japerry’s picture

Did a bit of reformatting and committed the change to this:

  if(defined('PHP_MAJOR_VERSION') && PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3) {
japerry’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.