0

I have a model called Api.

Which I'm accessing from a shell Script.

My shell script function that is running:

public function verifyTransactions(){
        $result =$this->out($this->Api->verifyNumber());
        $this->out(var_dump($result));
    }

this outputs]

int(2)

Here is the function in the Api model:

    public function verifyNumber(){
    return null;
}

I've tried making return null into return false (boolean) , return a string like "jibberish"

But still when I print it out I get the type as int with a different number in, like an object reference or something.

I'm sure I've over looked something real simple, if somebody could point it out that would be awesome ;)

Thanks

Edit:

Ah the error is I've got $this->out in there twice

2 Answers 2

1

If you are not going to output the returned (null) value and just want to use it for comparisions, why not avoid using $this->out alltogether?

Leave your Api method exactly the same and the verifyTransaction method could simply be ...

public function verifyTransactions(){
    var_dump($this->Api->verifyNumber());
}

Or ..

public function verifyTransactions(){
    if(is_null($this->Api->verifyNumber()){
        //do null stuff. Could even use the out method you have been trying to avoid...
        $this->out('got null back from Api');
    }
}

Currently you are setting a variable with the $this->out helper... $this->out is meant for handling readable output, never for setting variables... Don't do ...

 $result =$this->out($this->Api->verifyNumber());

Just ...

 $result = $this->Api->verifyNumber();
Sign up to request clarification or add additional context in comments.

Comments

1

Shell::out() returns the number of bytes written or false on error, so I'm not sure why you would expect it to return something else.

See http://api.cakephp.org/2.4/class-Shell.html#_out

If you need to reuse the return value of Api::verifyNumber(), then you should directly store it in a variable first.

public function verifyTransactions(){
    $result = $this->Api->verifyNumber();
    $this->out($result);
    // ...
}

Comments

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.