|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
here is my simple email lib: http://pastebin.com/m4d107c01
any idea why in the body i have a link with an = sign that gets replaced with a % sign? -e |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Friday 14 March 2008 18:33:13 nihilism machine wrote:
> here is my simple email lib: http://pastebin.com/m4d107c01 > > any idea why in the body i have a link with an = sign that gets > replaced with a % sign? > > -e read up on urlencode -- --- Børge Holen http://www.arivene.net |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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 > |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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 <mailist@ericgorr.net> 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 > > |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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/ |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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 <mailist@ericgorr.net> > 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 > > |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
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 <mailist@ericgorr.net> 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 |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
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. <?php if (rand(0,1) == 0) { function arse() { echo "arse 1\n"; } } else { function arse() { echo "arse 2\n"; } } arse(); ?> Oh, and top-posting is evil, please don't do it. -Stut -- http://stut.net/ |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
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. > > <?php > 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 |
|
|
|
#12 |
|
Messages: n/a
Hébergeur: |
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. >> >> <?php >> 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. <?php 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 |
|
|
|
#13 |
|
Messages: n/a
Hébergeur: |
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. >>> >>> <?php >>> 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. > > <?php > 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? <?php class TestClass { function arse() { if ( rand(0,1) == 0 ) { echo "arse 1\n"; } else { echo "arse 2\n"; } } } $myVar = new TestClass; $myVar->arse(); ?> |
|
|
|
#14 |
|
Messages: n/a
Hébergeur: |
OK, here's how it goes:
<?php if(!defined('_THIS_PHP_FILE_PHP')) { define('_THIS_PHP_FILE_PHP', true); // define your classes and functions here } // endif _THIS_PHP_FILE_PHP ?> |
|
|
|
#15 |
|
Messages: n/a
Hébergeur: |
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. >>> >>> <?php >>> 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. > > <?php > 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(); > ?> 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 you find a better way. -Stut -- http://stut.net/ |
|
|
|
#16 |
|
Messages: n/a
Hébergeur: |
> -----Original Message-----
> From: Eric Gorr [mailto:mailist@ericgorr.net] > 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. > >> > >> <?php > >> 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. > > <?php > 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: <?php ob_start(); ?> class TestClass { <?php if ( rand(0,1) == 0 ) { ?> function arse() { echo "arse 1\n"; } <?php } else { ?> function arse() { echo "arse 2\n"; } <?php } ?> } <?php // Fetch class definition in the output buffer; $classDef = ob_get_clean(); // Define class eval($classDef); $myVar = new TestClass; $myVar->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: info@bestplace.net | MSN Chat: best@bestplace.net | SKYPE: bestplace | Web: bestplace.biz | Web: seo-diy.com |
|
|
|
#17 |
|
Messages: n/a
Hébergeur: |
On Mar 14, 2:19 pm, mail...@ericgorr.net (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. This is part of the C compiler pragmas. But I am relatively new to the PHP language, but I don't believe PHP supports pragmas. I use pragma all the time in my C/C++ code. When testing or exploring logic, I just surround code with if (true|false) {} wrappers and might use defines as well, example: define("USE_SPECIAL_CODE", false); .... if (USE_SPECIAL_CODE) { } else { } or something like: if (0) { original logic } some new version of your logic Yes, not the same thing. But you if you are distributing this stuff, unless the logic is an useable and optional part of the application, you don't want to include these snippets in your distribution anyway. After all, PHP is not distributed as compiled code ... not yet atleast. :-) |
|
![]() |
| Outils de la discussion | |
|
|