RE: Ternary operators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Well, I tried something simple...

$ php -r 'echo "hello world\n";'
Error in argument 1, char 2: option not found r
Error in argument 1, char 2: option not found r
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
       php <file> [args...]
  -a               Run interactively
  -C               Do not chdir to the script's directory
  -c <path>|<file> Look for php.ini file in this directory
  -n               No php.ini file will be used
  -d foo[=bar]     Define INI entry foo with value 'bar'
  -e               Generate extended information for debugger/profiler
  -f <file>        Parse <file>.  Implies `-q'
  -h               This help
  -i               PHP information
  -l               Syntax check only (lint)
  -m               Show compiled in modules
  -q               Quiet-mode.  Suppress HTTP Header output.
  -s               Display colour syntax highlighted source.
  -v               Version number
  -w               Display source with stripped comments and whitespace.
  -z <file>        Load Zend extension <file>.


This means my install can't run inline stuff like this? Guess it wasn't set
up to do that. So no I won't say that I will use php -r to test anything..
lol :)

Still, thanks for your help, I was playing around with it and wanted to see
what other cool stuff you could do. 

Carl Furst


> -----Original Message-----
> From: Jochem Maas [mailto:jochem@xxxxxxxxxxxxx]
> Sent: Wednesday, February 15, 2006 3:55 PM
> To: Carl Furst
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  Ternary operators
> 
> Carl Furst wrote:
> > Hey all,
> >
> > Question about ternary operators. You can't really use functions INSIDE
> > ternary operators, right? They can only be tokens and operators?
> >
> > So
> >
> >
> > $fabulous = true;
> >
> > $fabulous ? echo "I am fabulous!\n" : echo "I am a looser!\n";
> >
> > Would not work?
> 
> testing this is quite easy (given your reference to backtick syntax):
> 
> 
> $> php -r '$fabulous = true;$fabulous ? echo "I am fabulous!\n" : echo "I
> am a looser!\n";'
> 
> Parse error: parse error, unexpected T_ECHO in Command line code on line 1
> 
> 
> >
> > And this:
> >
> > echo  $fabulous ? "I am fabulous!\n" : "I am a looser!\n";
> >
> > would?
> 
> 
> $> php -r '$fabulous = true; echo $fabulous ? "I am fabulous!\n" : "I am a
> looser!\n";'
> I am fabulous!
> 
> 
> >
> > Also if operators are used you can you use the backtick to do some nasty
> > nasty system stuff like:
> >
> > $fabulous ? `rm -Rf ~` : `shutdown --now`;
> 
> 
> $> php -r '$fabulous = true; echo $fabulous ? `echo TOOL` : `echo tool`;'
> TOOL
> 
> >
> > So would it ever be contrary to allow the ternary operator to do
> different
> > functions on different evaluations of the Boolean Expression at the
> > beginning; like in the first example?
> 
> yes and no. echo is not a function, it's a language construct.
> you can do stuff like:
> 
> $> php -r '
> function func1() { echo "TRUE\n"; }
> function func2() { echo "FALSE\n"; }
> 
> $f = true; $f ? func1(): func2();
> '
> TRUE
> 
> please say your going start using "php -r" to test stuff like this. :-)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux