2

I have a custom helper and a config, I can get the value but when I try the isset() it's not working and it shows me like this

enter image description here

and this is the content of customer helper: app\helper\LmsHelper.php

class LmsHelper
{   
    private static $host;
    private static $api_key;
    private static $api_version;
    private static $use_ssl;
    private static $debug;
    private static $port;

    public function __construct() {
        self::$host         = Config::get('lms.host');
        self::$api_key      = Config::get('lms.api_key');
        self::$api_version  = Config::get('lms.api_version');
        self::$use_ssl      = Config::get('lms.use_ssl');
        self::$debug        = isset(Config::get('lms.debug')) ? Config::get('lms.debug') : false;


        if (isset(Config::get('lms.port'))) {
            self::$port = Config::get('lms.port');
        } else {
            self::$port = self::$use_ssl ? 443 : 80;
        }
    }
}

and app\config\lms.php

<?php

return array( 
    'host' => 'www.themartialarts.university', 
    'api_key' => '6027-178512-e272b9afac4763199fa8d79e4bc0dcb39a378658', 
    'api_version' => '1', 
    'use_ssl' => true,
);

any idea what other method I can do? cause this is from normal PHP and I convert it into Laravel.

Storm Spirit
  • 1,440
  • 4
  • 19
  • 42
  • I think you should not use the "isset" function, as explained here http://stackoverflow.com/questions/11464714/php-check-if-false-or-null – ddb Jul 04 '16 at 08:31

5 Answers5

3

Use the Config::has("name") method call since it's a method call you can't use isset().

Philip Rollins
  • 1,271
  • 8
  • 19
1

You can only call isset on $variables.

Change that line to self::$debug = Config::get('lms.debug', false); to solve the problem. (set the default value to false)

Niclas Larsson
  • 1,317
  • 8
  • 13
0

The " isset " takes only variable. You must set the result of your function in a prior varriable.

 public function __construct() {
    $config = Config::get('lms.debug');
    self::$host         = Config::get('lms.host');
    self::$api_key      = Config::get('lms.api_key');
    self::$api_version  = Config::get('lms.api_version');
    self::$use_ssl      = Config::get('lms.use_ssl');
    self::$debug        = isset($config) ? Config::get('lms.debug') : false;

    $configPort = Config::get('lms.port');
    if (isset($configPort)) {
        self::$port = Config::get('lms.port');
    } else {
        self::$port = self::$use_ssl ? 443 : 80;
    }
}
DevLoots
  • 747
  • 1
  • 6
  • 21
0

Even if the language construct supported it, it doesn't make much sense to test whether the function returns a variable because even missing return clauses generate a proper null. E.g.:

function nothing() {
}

var_dump( nothing() );
NULL

I suspect you want to use is_null() rather than isset().

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0

Use if instead of isset as isset is used to check a variable is set and is not NULL.

Ravi Hirani
  • 6,511
  • 1
  • 27
  • 42