PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > email issue
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
email issue

Réponse
 
LinkBack Outils de la discussion
Vieux 14/03/2008, 18h33   #1
nihilism machine
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut email issue

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
  Réponse avec citation
Vieux 14/03/2008, 19h02   #2
Børge Holen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] email issue

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
  Réponse avec citation
Vieux 14/03/2008, 19h19   #3
Eric Gorr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut PHP and #if

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.

  Réponse avec citation
Vieux 14/03/2008, 19h22   #4
Børge Holen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
  Réponse avec citation
Vieux 14/03/2008, 19h34   #5
Eric Gorr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
>


  Réponse avec citation
Vieux 14/03/2008, 19h38   #6
Dave Goodchild
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
>
>


  Réponse avec citation
Vieux 14/03/2008, 19h42   #7
Stut
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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/
  Réponse avec citation
Vieux 14/03/2008, 20h03   #8
Eric Gorr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
>
>


  Réponse avec citation
Vieux 14/03/2008, 20h08   #9
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
  Réponse avec citation
Vieux 14/03/2008, 20h10   #10
Stut
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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/
  Réponse avec citation
Vieux 14/03/2008, 20h15   #11
Eric Gorr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if


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


  Réponse avec citation
Vieux 14/03/2008, 20h21   #12
Eric Gorr
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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


  Réponse avec citation
Vieux 14/03/2008, 20h32   #13
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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();
?>
  Réponse avec citation
Vieux 14/03/2008, 20h33   #14
André Medeiros
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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
?>
  Réponse avec citation
Vieux 14/03/2008, 20h51   #15
Stut
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] PHP and #if

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/
  Réponse avec citation
Vieux 14/03/2008, 21h23   #16
Andrés Robinet
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] PHP and #if

> -----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



  Réponse avec citation
Vieux 16/03/2008, 09h51   #17
Hector Santos
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: PHP and #if

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. :-)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h47.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,25642 seconds with 25 queries