1

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.

1

5 Answers 5

3

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

Sign up to request clarification or add additional context in comments.

Comments

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)

Comments

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().

Comments

0

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

Comments

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;
    }
}

1 Comment

What about if (isset(Config::get('lms.port'))) {? :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.