E
E
Emil Rakhmatullin2019-03-22 11:28:04
PHP
Emil Rakhmatullin, 2019-03-22 11:28:04

(RedBeanPHP) Why am I getting NULL?

Output functions:

function showService()
  {
    $services = R::load( 'services', 4 );
    return $services;
  }

  function index()
  {
    $link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    if( $link == 'http://'.$_SERVER['HTTP_HOST'].'/service.php' )
    {
      showService();
      //createService();
    }else{}
  }

And after: But it contains NULL, and if you output it in the library itself, then it will be what you need. What's the matter?
<?php echo $services->title; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2019-03-22
@FanatPHP

Who teaches you all red bin, without letting you read the PHP primer?
First we read about the scope
Then we start such an interesting process as "thinking":
we look at the code
and think why on earth we will have the $services variable here after calling this function. Answer: none.
After that, we read about returning values ​​from functions and again think about how we can get the value that the function returns to us into the variable. so that later we can finally use this variable.
Hint: You can see an example in the third line of the code in the question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question