Welcome Guest, Not a member yet? Register   Sign In
Cannot use isset to check for segment.. Why not?
#1

(This post was last modified: 02-17-2016, 05:57 PM by cupboy.)

Cannot do this:
if (isset($this->uri->segment(1))) //   Can't use method return value in write context in....

But this is OK:
if ($this->uri->segment(1))

Anyone know the reason? I don't know what the "write context" error means.

Here is some similar code in system library (although it has no parameter, maybe that's the difference):
if ( ! isset($this->lib_name))
Reply
#2

To simplify the meaning of the error, it is saying that $this->uri->segment(1) is not a variable, or something that can be checked with isset. segment() is a method in the URI class, and has it's own way of passing back a value to show if it is set. What you can do is this:


PHP Code:
if( $seg1 $this->uri->segment(1) )
{
  // ...

Reply
#3

(02-17-2016, 05:53 PM)cupboy Wrote: Cannot do this:
if (isset($this->uri->segment(1))) //   Can't use method return value in write context in....

But this is OK:
if ($this->uri->segment(1))

Anyone know the reason? I don't know what the "write context" error means.

Here is some similar code in system library (although it has no parameter, maybe that's the difference):
if ( ! isset($this->lib_name))

What you could do is

PHP Code:
$uri_segment_1 $this->uri->segment(1);

if (isset(
$uri_segment_1)) {


There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB