RE: [PHP] PHP and #if

2008-03-14 Thread Andrés Robinet
> -Original Message-
> From: Eric Gorr [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 14, 2008 3:22 PM
> To: PHP General
> Subject: Re: [PHP] PHP and #if
> 
> 
> On Mar 14, 2008, at 3:15 PM, Eric Gorr wrote:
> 
> >
> > On Mar 14, 2008, at 3:10 PM, Stut wrote:
> >
> >> On 14 Mar 2008, at 19:03, Eric Gorr wrote:
> >>> Unfortunately, such things cannot be used to wrap functions.
> >>
> >> Erm, yes they can. Try it.
> >>
> >>  >>   if (rand(0,1) == 0)
> >>   {
> >>   function arse()
> >>   {
> >>   echo "arse 1\n";
> >>   }
> >>   }
> >>   else
> >>   {
> >>   function arse()
> >>   {
> >>   echo "arse 2\n";
> >>   }
> >>   }
> >>
> >>   arse();
> >> ?>
> >>
> >
> > Gives:
> >
> > Parse error: syntax error, unexpected T_STRING in /Users/Eric/Sites/
> > ifWrapping.php on line 3
> 
> Oh, sorry, apparently there are some invisible characters in the text
> you pasted which I had to zap first. Yes, this does work as expected.
> 
> However, try wrapping the arse function in a class.
> 
>  class TestClass
> {
>   if ( rand(0,1) == 0 )
>   {
>   function arse()
>   {
>   echo "arse 1\n";
>   }
>   }
>   else
>   {
>   function arse()
>   {
>   echo "arse 2\n";
>   }
>   }
> 
> }
> 
> $myVar = new TestClass;
> 
> $myVar->arse();
> ?>
> 
> 
> That fails with:
> 
> 
> Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in /
> Users/Eric/Sites/ifWrapping.php on line 4
> 
> 
> 

Mmmm... why would you want to use a different class definition on some
conditions? Yes, there might be reasons, but it's usually just a matter of
realizing that you can use inheritance, containment or some design patterns
(say, the Adapter pattern).
There are other ways to solve the problem which are not yet available in PHP.
Some of them are being discussed nowadays
(http://wiki.php.net/rfc/nonbreakabletraits).
Now, if you want something weird... I believe this would work:


 class TestClass
 {

function arse()
{
echo "arse 1\n";
}

function arse()
{
echo "arse 2\n";
}

 
 }
arse();
?>

I didn't test this, but it should work I think... I remember nuSoap doing
something similar for soap proxys (though not using output buffering). There are
alternatives that are way better (and smarter about performance) than this,
but... you see... everything can be done in PHP.

If you look for "build-like" tools, that is, generate code at "deployment-time",
you may try phing http://phing.info.

Regards,

Rob

Andrés Robinet | Lead Developer | BESTPLACE CORPORATION 
5100 Bayview Drive 206, Royal Lauderdale Landings, Fort Lauderdale, FL 33308 |
TEL 954-607-4296 | FAX 954-337-2695 | 
Email: [EMAIL PROTECTED]  | MSN Chat: [EMAIL PROTECTED]  |  SKYPE: bestplace |
 Web: bestplace.biz  | Web: seo-diy.com




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



Re: [PHP] PHP and #if

2008-03-14 Thread Stut

On 14 Mar 2008, at 19:21, Eric Gorr wrote:

On Mar 14, 2008, at 3:15 PM, Eric Gorr wrote:

On Mar 14, 2008, at 3:10 PM, Stut wrote:

On 14 Mar 2008, at 19:03, Eric Gorr wrote:

Unfortunately, such things cannot be used to wrap functions.


Erm, yes they can. Try it.





Gives:

Parse error: syntax error, unexpected T_STRING in /Users/Eric/Sites/ 
ifWrapping.php on line 3


Oh, sorry, apparently there are some invisible characters in the  
text you pasted which I had to zap first. Yes, this does work as  
expected.


However, try wrapping the arse function in a class.

arse();
?>


In my experience there are very few valid reasons for conditionally  
defining functions, and even fewer for conditionally defining methods  
in a class. Maybe if you explain what you're trying to achieve we can  
help you find a better way.


-Stut

--
http://stut.net/

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



Re: [PHP] PHP and #if

2008-03-14 Thread André Medeiros
OK, here's how it goes:



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



Re: [PHP] PHP and #if

2008-03-14 Thread Shawn McKenzie
Eric Gorr wrote:
> 
> On Mar 14, 2008, at 3:15 PM, Eric Gorr wrote:
> 
>>
>> On Mar 14, 2008, at 3:10 PM, Stut wrote:
>>
>>> On 14 Mar 2008, at 19:03, Eric Gorr wrote:
 Unfortunately, such things cannot be used to wrap functions.
>>>
>>> Erm, yes they can. Try it.
>>>
>>> >>   if (rand(0,1) == 0)
>>>   {
>>>   function arse()
>>>   {
>>>   echo "arse 1\n";
>>>   }
>>>   }
>>>   else
>>>   {
>>>   function arse()
>>>   {
>>>   echo "arse 2\n";
>>>   }
>>>   }
>>>
>>>   arse();
>>> ?>
>>>
>>
>> Gives:
>>
>> Parse error: syntax error, unexpected T_STRING in
>> /Users/Eric/Sites/ifWrapping.php on line 3
> 
> Oh, sorry, apparently there are some invisible characters in the text
> you pasted which I had to zap first. Yes, this does work as expected.
> 
> However, try wrapping the arse function in a class.
> 
>  class TestClass
> {
> if ( rand(0,1) == 0 )
> {
> function arse()
> {
> echo "arse 1\n";
> }
> }
> else
> {
> function arse()
> {
> echo "arse 2\n";
> }
> }
> 
> }
> 
> $myVar = new TestClass;
> 
> $myVar->arse();
> ?>
> 
> 
> That fails with:
> 
> 
> Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in
> /Users/Eric/Sites/ifWrapping.php on line 4
> 
> 
Never tried it in a class.  There is probably a way to hack and get it
to work.  However, unless you're doing something so much more
sophisticated than most people, what's wrong with this?

arse();
?>

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



Re: [PHP] PHP and #if

2008-03-14 Thread Eric Gorr


On Mar 14, 2008, at 3:15 PM, Eric Gorr wrote:



On Mar 14, 2008, at 3:10 PM, Stut wrote:


On 14 Mar 2008, at 19:03, Eric Gorr wrote:

Unfortunately, such things cannot be used to wrap functions.


Erm, yes they can. Try it.





Gives:

Parse error: syntax error, unexpected T_STRING in /Users/Eric/Sites/ 
ifWrapping.php on line 3


Oh, sorry, apparently there are some invisible characters in the text  
you pasted which I had to zap first. Yes, this does work as expected.


However, try wrapping the arse function in a class.

arse();
?>


That fails with:


Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in / 
Users/Eric/Sites/ifWrapping.php on line 4




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



Re: [PHP] PHP and #if

2008-03-14 Thread Eric Gorr


On Mar 14, 2008, at 3:10 PM, Stut wrote:


On 14 Mar 2008, at 19:03, Eric Gorr wrote:

Unfortunately, such things cannot be used to wrap functions.


Erm, yes they can. Try it.





Gives:

Parse error: syntax error, unexpected T_STRING in /Users/Eric/Sites/ 
ifWrapping.php on line 3




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



Re: [PHP] PHP and #if

2008-03-14 Thread Stut

On 14 Mar 2008, at 19:03, Eric Gorr wrote:

Unfortunately, such things cannot be used to wrap functions.


Erm, yes they can. Try it.



Oh, and top-posting is evil, please don't do it.

-Stut

--
http://stut.net/

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



Re: [PHP] PHP and #if

2008-03-14 Thread Shawn McKenzie
Eric Gorr wrote:
> Unfortunately, such things cannot be used to wrap functions.
> 
> 
> 
> On Mar 14, 2008, at 2:38 PM, Dave Goodchild wrote:
> 
>> in php you have a number of constructs that can be used to execute
>> code (or not) based on certain conditions ie is_defined(). Not sure if
>> the comparison with C holds true as C is compiled and PHP is interpreted.
>>
>> On Fri, Mar 14, 2008 at 6:34 PM, Eric Gorr <[EMAIL PROTECTED]> wrote:
>> If you are talking about simply commenting code out, yes, I am aware
>> of this...however, the #if technique is far more capable in certain
>> situations.
>>
>> There are reasons why C, etc. has included the ability to comment out
>> lines of code and also provide #if's.
>>
>> But based on your reply, I have to assume that PHP does not current
>> provide such a technique...as I suspected.
>>
>>
>> On Mar 14, 2008, at 2:22 PM, Børge Holen wrote:
>>
>> > On Friday 14 March 2008 19:19:30 Eric Gorr wrote:
>> >> In C, etc. one can place #if's around code to determine whether or
>> >> not
>> >> the compiler should pay any attention to the code.
>> >>
>> >> Is there a similar technique for PHP?
>> >>
>> >> I've not seen anything like this before and a brief search hasn't
>> >> turned up anything either...just thought I would ask to make sure.
>> >
>> > # Notin' here
>> > // here neither
>> > */
>> > Nor there
>> > /*
>> >
>> > --
>> > ---
>> > Børge Holen
>> > http://www.arivene.net
>> >
>> > --
>> > PHP General Mailing List (http://www.php.net/)
>> > To unsubscribe, visit: http://www.php.net/unsub.php
>> >
>>
>>
>> -- 
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
> 
Surrounding a bit of code/function in an if statement in PHP does the
same thing as the #if in C because PHP is interpreted.

In C, if the #if is true then the compiler compiles the code and when
you execute the binary the code is executed, if the #if is false then
the code is not compiled so it can't execute because it isn't there.

In PHP, if you execute the script and the if is true then the code
executes, if the if is false then the code doesn't execute.

Same same...

-Shawn

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



Re: [PHP] PHP and #if

2008-03-14 Thread Eric Gorr

Unfortunately, such things cannot be used to wrap functions.



On Mar 14, 2008, at 2:38 PM, Dave Goodchild wrote:

in php you have a number of constructs that can be used to execute  
code (or not) based on certain conditions ie is_defined(). Not sure if
the comparison with C holds true as C is compiled and PHP is  
interpreted.


On Fri, Mar 14, 2008 at 6:34 PM, Eric Gorr <[EMAIL PROTECTED]>  
wrote:

If you are talking about simply commenting code out, yes, I am aware
of this...however, the #if technique is far more capable in certain
situations.

There are reasons why C, etc. has included the ability to comment out
lines of code and also provide #if's.

But based on your reply, I have to assume that PHP does not current
provide such a technique...as I suspected.


On Mar 14, 2008, at 2:22 PM, Børge Holen wrote:

> On Friday 14 March 2008 19:19:30 Eric Gorr wrote:
>> In C, etc. one can place #if's around code to determine whether or
>> not
>> the compiler should pay any attention to the code.
>>
>> Is there a similar technique for PHP?
>>
>> I've not seen anything like this before and a brief search hasn't
>> turned up anything either...just thought I would ask to make sure.
>
> # Notin' here
> // here neither
> */
> Nor there
> /*
>
> --
> ---
> Børge Holen
> http://www.arivene.net
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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





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



Re: [PHP] PHP and #if

2008-03-14 Thread Stut

On 14 Mar 2008, at 18:34, Eric Gorr wrote:
If you are talking about simply commenting code out, yes, I am aware  
of this...however, the #if technique is far more capable in certain  
situations.


There are reasons why C, etc. has included the ability to comment  
out lines of code and also provide #if's.


But based on your reply, I have to assume that PHP does not current  
provide such a technique...as I suspected.


PHP has no built-in macro language. I started to write a pre-processor  
a while ago but didn't get very far before the real world forced me to  
shelve it, but such a beast is pretty simple to write but obviously is  
not evaluated at runtime.


IIRC there was a project a while ago to build a macro language into  
PHP but I have no idea how far it got. I think it was being done under  
the GSoC initiative. Google should have more on that.


-Stut

--
http://stut.net/

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



Re: [PHP] PHP and #if

2008-03-14 Thread Dave Goodchild
in php you have a number of constructs that can be used to execute code (or
not) based on certain conditions ie is_defined(). Not sure if
the comparison with C holds true as C is compiled and PHP is interpreted.

On Fri, Mar 14, 2008 at 6:34 PM, Eric Gorr <[EMAIL PROTECTED]> wrote:

> If you are talking about simply commenting code out, yes, I am aware
> of this...however, the #if technique is far more capable in certain
> situations.
>
> There are reasons why C, etc. has included the ability to comment out
> lines of code and also provide #if's.
>
> But based on your reply, I have to assume that PHP does not current
> provide such a technique...as I suspected.
>
>
> On Mar 14, 2008, at 2:22 PM, Børge Holen wrote:
>
> > On Friday 14 March 2008 19:19:30 Eric Gorr wrote:
> >> In C, etc. one can place #if's around code to determine whether or
> >> not
> >> the compiler should pay any attention to the code.
> >>
> >> Is there a similar technique for PHP?
> >>
> >> I've not seen anything like this before and a brief search hasn't
> >> turned up anything either...just thought I would ask to make sure.
> >
> > # Notin' here
> > // here neither
> > */
> > Nor there
> > /*
> >
> > --
> > ---
> > Børge Holen
> > http://www.arivene.net
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] PHP and #if

2008-03-14 Thread Eric Gorr
If you are talking about simply commenting code out, yes, I am aware  
of this...however, the #if technique is far more capable in certain  
situations.


There are reasons why C, etc. has included the ability to comment out  
lines of code and also provide #if's.


But based on your reply, I have to assume that PHP does not current  
provide such a technique...as I suspected.



On Mar 14, 2008, at 2:22 PM, Børge Holen wrote:


On Friday 14 March 2008 19:19:30 Eric Gorr wrote:
In C, etc. one can place #if's around code to determine whether or  
not

the compiler should pay any attention to the code.

Is there a similar technique for PHP?

I've not seen anything like this before and a brief search hasn't
turned up anything either...just thought I would ask to make sure.


# Notin' here
// here neither
*/
Nor there
/*

--
---
Børge Holen
http://www.arivene.net

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




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



Re: [PHP] PHP and #if

2008-03-14 Thread Børge Holen
On Friday 14 March 2008 19:19:30 Eric Gorr wrote:
> In C, etc. one can place #if's around code to determine whether or not
> the compiler should pay any attention to the code.
>
> Is there a similar technique for PHP?
>
> I've not seen anything like this before and a brief search hasn't
> turned up anything either...just thought I would ask to make sure.

# Notin' here
// here neither
*/
Nor there
/*

-- 
---
Børge Holen
http://www.arivene.net

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



[PHP] PHP and #if

2008-03-14 Thread Eric Gorr
In C, etc. one can place #if's around code to determine whether or not  
the compiler should pay any attention to the code.


Is there a similar technique for PHP?

I've not seen anything like this before and a brief search hasn't  
turned up anything either...just thought I would ask to make sure.



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



[PHP] PHP and if statement if a page isnt there using iframes

2002-04-18 Thread Craig

i am using iframes to display a page within a page
the iframe is named and the page is dynamic
the iframe displays a page using generated php.

is there a way of using php to redirect to "nopage.php" if the page does not
exist?



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