php-general Digest 17 Apr 2008 07:48:09 -0000 Issue 5409

Topics (messages 273121 through 273144):

Newbie question about sending email
        273121 by: Pete Holsberg
        273122 by: Daniel Brown
        273123 by: Pete Holsberg
        273124 by: Daniel Brown
        273125 by: Pete Holsberg
        273127 by: Daniel Brown

Re: PHP with NNTP?
        273126 by: Stut
        273129 by: vester_s
        273143 by: Per Jessen

Re: Database abstraction?
        273128 by: Chris
        273137 by: Nathan Nobbe
        273138 by: Jason Pruim
        273142 by: Chris

Query in Query problems
        273130 by: VamVan
        273131 by: Chris

Re: What is the practical use of "abstract" and "interface"?
        273132 by: Jochem Maas
        273133 by: Daevid Vincent
        273136 by: Nathan Nobbe

PHP_OUTPUT_HANDLER_START et al
        273134 by: Richard Lynch

Re: Reserved var for checking remote IP address
        273135 by: Spamm Trappe

& performance issues
        273139 by: Nathan Nobbe
        273141 by: Robert Cummings

Re: PHP Serialization Performance
        273140 by: Casey

FRench characters not displayed correctly
        273144 by: Angelo Zanetti

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message --- I wanted a form for people in my community to use to subscribe to a yahoo group that I run.

Not being a PHP programmer, I created the form with phpFormGenerator from SourceForge.

It works fine except that the email that gets sent to yahoo appears to come from my web host's domain!

How can I change things so that the email appears to come from the email address that is entered in the form?

Thanks.

--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 3:53 PM, Pete Holsberg <[EMAIL PROTECTED]> wrote:
> I wanted a form for people in my community to use to subscribe to a yahoo
> group that I run.
>
>  Not being a PHP programmer, I created the form with phpFormGenerator from
> SourceForge.
>
>  It works fine except that the email that gets sent to yahoo appears to come
> from my web host's domain!
>
>  How can I change things so that the email appears to come from the email
> address that is entered in the form?

    Make sure that the From:, Reply-To:, and Return-Path: headers are
correctly set in the form processing code, that the headers in general
are properly constructed, and that your host allows aliased sending by
configuration (some MTA configurations only allow a single address, to
reduce SPAM and such).

-- 
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!

--- End Message ---
--- Begin Message ---
Daniel Brown has written on 4/16/2008 4:04 PM:
On Wed, Apr 16, 2008 at 3:53 PM, Pete Holsberg <[EMAIL PROTECTED]> wrote:
I wanted a form for people in my community to use to subscribe to a yahoo
group that I run.

 Not being a PHP programmer, I created the form with phpFormGenerator from
SourceForge.

 It works fine except that the email that gets sent to yahoo appears to come
from my web host's domain!

 How can I change things so that the email appears to come from the email
address that is entered in the form?

    Make sure that the From:, Reply-To:, and Return-Path: headers are
correctly set in the form processing code, that the headers in general
are properly constructed, and that your host allows aliased sending by
configuration (some MTA configurations only allow a single address, to
reduce SPAM and such).

The entire processor.php file is:

<?php

$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

mail("[EMAIL PROTECTED],[EMAIL PROTECTED]","SUBSCRIBE","Form data:

Name: " . $_POST['field_1'] . "
Street Address: " . $_POST['field_2'] . "
Phone Number: " . $_POST['field_3'] . "
Email Address: " . $_POST['field_4'] . "


powered by phpFormGenerator.
");

include("confirm.html");

?>

--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 4:39 PM, Pete Holsberg <[EMAIL PROTECTED]> wrote:
>
>  The entire processor.php file is:
>
>  <?php
>
>
> $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
>
>  mail("[EMAIL PROTECTED],[EMAIL PROTECTED]","SUBSCRIBE","Form
> data:
>
>  Name: " . $_POST['field_1'] . "
>  Street Address: " . $_POST['field_2'] . "
>  Phone Number: " . $_POST['field_3'] . "
>  Email Address: " . $_POST['field_4'] . "
>
>
>  powered by phpFormGenerator.
>  ");
>
>  include("confirm.html");
>
>  ?>

    Note the mail() parameters.  There's no header information there.

    In your HTML form, add the following field (dress up the HTML as
needed to fit with your form):

<input type="text" name="from_addr">

    Then, change the email processing code to the following:

<?php

$where_form_is =
"http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/";
$to = "[EMAIL PROTECTED],[EMAIL PROTECTED]";
$subject = "SUBSCRIBE";
$from = $_POST['from_addr'];
$body = "Form data:

Name: ".$_POST['field_1']."
Email: ".$_POST['from_addr']."
Street Address: ".$_POST['field_2']."
Phone Number: ".$_POST['field_3']."
Email Address: ".$_POST['field_4']."

powered by phpFormGenerator, but fixed by PHP-General!";

$headers  = "From: \"".$_POST['field_1']."\" <".$_POST['from_addr'].">\r\n";
$headers .= "X-Mailer: PHP/".phpversion()."\r\n";

include("confirm.html");

?>

    Keep in mind, though, that there's no validation and no SPAM
protection there, but if you're letting Yahoo! manage the group, it's
not *quite* as big of a deal.  You may notice SPAM coming through to
the @pobox.com address from the form though.

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
Daniel Brown has written on 4/16/2008 4:56 PM:
On Wed, Apr 16, 2008 at 4:39 PM, Pete Holsberg <[EMAIL PROTECTED]> wrote:
 The entire processor.php file is:

 <?php


$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

 mail("[EMAIL PROTECTED],[EMAIL PROTECTED]","SUBSCRIBE","Form
data:

 Name: " . $_POST['field_1'] . "
 Street Address: " . $_POST['field_2'] . "
 Phone Number: " . $_POST['field_3'] . "
 Email Address: " . $_POST['field_4'] . "


 powered by phpFormGenerator.
 ");

 include("confirm.html");

 ?>

    Note the mail() parameters.  There's no header information there.

    In your HTML form, add the following field (dress up the HTML as
needed to fit with your form):

<input type="text" name="from_addr">

    Then, change the email processing code to the following:

<?php

$where_form_is =
"http://".$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF'])."/";
$to = "[EMAIL PROTECTED],[EMAIL PROTECTED]";
$subject = "SUBSCRIBE";
$from = $_POST['from_addr'];
$body = "Form data:

Name: ".$_POST['field_1']."
Email: ".$_POST['from_addr']."
Street Address: ".$_POST['field_2']."
Phone Number: ".$_POST['field_3']."
Email Address: ".$_POST['field_4']."


Why do I need both from_addr and field_4 (Email Address)? Could I just use

$from = $_POST['field_4']?

Thanks.


--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 5:14 PM, Pete Holsberg <[EMAIL PROTECTED]> wrote:
>
>  Why do I need both from_addr and field_4 (Email Address)? Could I just use
>
>  $from = $_POST['field_4']?

    Sorry, I noticed it after I started rewriting the form processor,
and then forgot to edit the email accordingly.

    That's correct.  Where I placed the $_POST['from_addr'] stuff,
just replace it with $_POST['field_4'].  And then, of course, you can
ignore the HTML field-adding section of my previous email.

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

--- End Message ---
--- Begin Message ---
On 16 Apr 2008, at 18:01, vester_s wrote:
Is it possible to do it without using imap? I am trying to get the list of
all users that is on the newsgroup, is that possible?

I'm wondering what possible legitimate reason you could have for wanting that list?

There is a way to get it (it's not easy but it's possible) but until I know why you want it I'm not sharing.

-Stut

--
http://stut.net/

chris smith-9 wrote:

vester_s wrote:
Hi,

Can anybody tell me how can php connect to NNTP to get the list of all
users
in the newsgroups?

http://php.net/imap supports nntp.

--
Postgresql & php tutorials
http://www.designmagick.com/

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




--
View this message in context: 
http://www.nabble.com/PHP-with-NNTP--tp16713817p16723692.html
Sent from the PHP - General mailing list archive at Nabble.com.


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



--- End Message ---
--- Begin Message ---
I need to get the list for all of the people that subscribing to this
newsreader, this list will be used to modify the other mailing list
programs.

Basically by getting the list of the people that subscribing on this
newsgroup, then i could migrate it to our new forum based.

So is it possible for getting those list?

thanks,



Stut wrote:
> 
> On 16 Apr 2008, at 18:01, vester_s wrote:
>> Is it possible to do it without using imap? I am trying to get the  
>> list of
>> all users that is on the newsgroup, is that possible?
> 
> I'm wondering what possible legitimate reason you could have for  
> wanting that list?
> 
> There is a way to get it (it's not easy but it's possible) but until I  
> know why you want it I'm not sharing.
> 
> -Stut
> 
> -- 
> http://stut.net/
> 
>> chris smith-9 wrote:
>>>
>>> vester_s wrote:
>>>> Hi,
>>>>
>>>> Can anybody tell me how can php connect to NNTP to get the list of  
>>>> all
>>>> users
>>>> in the newsgroups?
>>>
>>> http://php.net/imap supports nntp.
>>>
>>> -- 
>>> Postgresql & php tutorials
>>> http://www.designmagick.com/
>>>
>>> -- 
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>>
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/PHP-with-NNTP--tp16713817p16723692.html
>> Sent from the PHP - General mailing list archive at Nabble.com.
>>
>>
>> -- 
>> 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
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-with-NNTP--tp16713817p16735336.html
Sent from the PHP - General mailing list archive at Nabble.com.


--- End Message ---
--- Begin Message ---
vester_s wrote:

> I need to get the list for all of the people that subscribing to this
> newsreader, this list will be used to modify the other mailing list
> programs.
> 
> Basically by getting the list of the people that subscribing on this
> newsgroup, then i could migrate it to our new forum based.
> 
> So is it possible for getting those list?

You can always check the news-server logfiles.  I think that's probably
the best place to get some user/usage information.  


/Per Jessen, Zürich


--- End Message ---
--- Begin Message ---
Jason Pruim wrote:
Hi Everyone!

I'm back with yet another question.... But getting closer to sounding like I know what I'm talking about and that's all thanks to all of you. A free beer (Or beverage of choice)* for everyone who has helped me over the years!

Here's my question... I have a program, where I want to take out the field names in a database table and display them... In other words instead of writing:
$Query ="SELECT First, Last, Middle, Add1 FROM mytable order by $order";

I want to write something more like:
$Query ="SELECT $FIELDNAMES FROM mytable order by $order";

So I need to know how to get the field names from the database so that I can populate $FIELDNAMES. I played a little bit and it looks like I might be able to get what I want by doing 2 queries...

$QueryFieldNames = "DESCRIBE $table";

And then some sort of a foreach or maybe a while to populate $FIELDNAMES? Maybe an array so I could do $FIELDNAMES['First'] if I needed to later.

then I can use my SELECT $FIELDNAMES FROM $table order by $order query to do my query...

If $FIELDNAMES contains all the fields, I have to ask why?

If you just want them for the header or something you could do something like this:

$fields = array();
$query = "select * from $table order by $order";
$result = mysql_query($query);

$row_counter = 0;
while ($row = mysql_fetch_assoc($result)) {
  if ($row_counter == 0) {
    $fields = array_keys($row);
  }
  print_r($row);
}

Haven't actually tested it but saves another round trip to the db.

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 1:30 PM, Richard Heyes <[EMAIL PROTECTED]> wrote:

> hope ya dont mind if i borrow that one :D
> >
>
> arm, have you seen my website...? :-)
>

umm; sry, havent :(

 i was reading through it, and i was like; holy shit; that dudes from the
> list !!  btw, i talked to the guy who wrote solar, when i was in dc last
> year.  really cool fellow; but i talked his ear off :O
>

Hope you reattached it for him... :-)


na; im holding onto it for him; hoping the next time i run into him i can
reattach it and start asking some more questions :)

-nathan

--- End Message ---
--- Begin Message ---

On Apr 16, 2008, at 5:37 PM, Chris wrote:

Jason Pruim wrote:
Hi Everyone!
I'm back with yet another question.... But getting closer to sounding like I know what I'm talking about and that's all thanks to all of you. A free beer (Or beverage of choice)* for everyone who has helped me over the years! Here's my question... I have a program, where I want to take out the field names in a database table and display them... In other words instead of writing: $Query ="SELECT First, Last, Middle, Add1 FROM mytable order by $order";
I want to write something more like:
$Query ="SELECT $FIELDNAMES FROM mytable order by $order";
So I need to know how to get the field names from the database so that I can populate $FIELDNAMES. I played a little bit and it looks like I might be able to get what I want by doing 2 queries...
$QueryFieldNames = "DESCRIBE $table";
And then some sort of a foreach or maybe a while to populate $FIELDNAMES? Maybe an array so I could do $FIELDNAMES['First'] if I needed to later. then I can use my SELECT $FIELDNAMES FROM $table order by $order query to do my query...

If $FIELDNAMES contains all the fields, I have to ask why?

What I am trying to accomplish is a customer wants me to add custom fields to their table in my database, I want to use the same code to display the separate fields... In other words right now I have the field names hard coded into my app.. I want to be able to remove the actual field names and have them pulled dynamically from the database, so it doesn't matter if there is 10 fields or 30 fields, it will print a header row that contains ALL the field names and format the table properly.

Does that help clarify?



If you just want them for the header or something you could do something like this:

$fields = array();
$query = "select * from $table order by $order";
$result = mysql_query($query);

$row_counter = 0;
while ($row = mysql_fetch_assoc($result)) {
 if ($row_counter == 0) {
   $fields = array_keys($row);
 }
 print_r($row);
}

Haven't actually tested it but saves another round trip to the db.

--
Postgresql & php tutorials
http://www.designmagick.com/



--- End Message ---
--- Begin Message ---
Jason Pruim wrote:

On Apr 16, 2008, at 5:37 PM, Chris wrote:

Jason Pruim wrote:
Hi Everyone!
I'm back with yet another question.... But getting closer to sounding like I know what I'm talking about and that's all thanks to all of you. A free beer (Or beverage of choice)* for everyone who has helped me over the years! Here's my question... I have a program, where I want to take out the field names in a database table and display them... In other words instead of writing:
$Query ="SELECT First, Last, Middle, Add1 FROM mytable order by $order";
I want to write something more like:
$Query ="SELECT $FIELDNAMES FROM mytable order by $order";
So I need to know how to get the field names from the database so that I can populate $FIELDNAMES. I played a little bit and it looks like I might be able to get what I want by doing 2 queries...
$QueryFieldNames = "DESCRIBE $table";
And then some sort of a foreach or maybe a while to populate $FIELDNAMES? Maybe an array so I could do $FIELDNAMES['First'] if I needed to later. then I can use my SELECT $FIELDNAMES FROM $table order by $order query to do my query...

If $FIELDNAMES contains all the fields, I have to ask why?

What I am trying to accomplish is a customer wants me to add custom fields to their table in my database, I want to use the same code to display the separate fields... In other words right now I have the field names hard coded into my app.. I want to be able to remove the actual field names and have them pulled dynamically from the database, so it doesn't matter if there is 10 fields or 30 fields, it will print a header row that contains ALL the field names and format the table properly.

Sure - but you can do it all in one go.

Another approach (which is database independent) is

select * from table limit 0;


Had to throw that in the mix :)

--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
Hello All,

We many times encounter the situations of having Queries inside loop of
another query. Many times we can solve the issue by query joins but there
will be some situations where we cannot do it.

For Example:

function Change($id){

        $qry_reg = "SELECT registrationID FROM registration  WHERE event_id
= '$id'";
        $res_reg =& $this->mdb2->query($qry_reg);

        while ($row_reg = $res_reg->fetchRow()) {
            $userid = $row_reg['registrationid'];
            $sql_insert = "INSERT
               INTO
               run
               (command, event_id, created, user_id, runtime)
               VALUES
               ('topic_change', '".$id."', NOW(), '".$userid."', NOW())";
                $res_insert =&  $this->mdb2->query($sql_insert);

        }
    }

How can we deal with this kind of stuff? My concern is to just use the query
once instead on burdening the Mysql Server with so many queries.... This is
just one case. How do we actually deal with these kind of situations?

Thanks

--- End Message ---
--- Begin Message ---
VamVan wrote:
Hello All,

We many times encounter the situations of having Queries inside loop of
another query. Many times we can solve the issue by query joins but there
will be some situations where we cannot do it.

For Example:

function Change($id){

        $qry_reg = "SELECT registrationID FROM registration  WHERE event_id
= '$id'";
        $res_reg =& $this->mdb2->query($qry_reg);

        while ($row_reg = $res_reg->fetchRow()) {
            $userid = $row_reg['registrationid'];
            $sql_insert = "INSERT
               INTO
               run
               (command, event_id, created, user_id, runtime)
               VALUES
               ('topic_change', '".$id."', NOW(), '".$userid."', NOW())";
                $res_insert =&  $this->mdb2->query($sql_insert);

        }
    }

In this example you can just use a single query:

$query = "insert into run(command, event_id, created, user_id, runtime)
select 'topic_change', registrationID, NOW(), ".(int)."$userid, NOW()
FROM registration WHERE event_id='".(int)$id."'";


--
Postgresql & php tutorials
http://www.designmagick.com/

--- End Message ---
--- Begin Message ---
seems nobody has a proper example of how
a defined abstract class and/or interface can actually
be usefu beyond documentation or compile time checks.

well consider this (no code, it would take too much I think):

1. a CMS that manages a dynamic, user-created tree of nodes, each
node containing 'something'
2. each node could be represented by an Object which implements
various Interfaces that determine what kind of output and admin
interface it had. (the CMS would know about registered Interfaces)
3. each afore mentioned Object could be of a subclass of a
abstract (to disallow instantion) base class that stipulated an
api and functionality that allowed the CMS to determine the
tree-interaction rules for the object, permissions, etc.

the idea being to allow a generic body of code to act on, in
a meaningful way (display,edit,publish,etc), a user-created tree of
objects so that no explicit knowledge of the available 'node classes'
is required. interaction would be based on the known interfaces
each object implements.

I know what mean atleast :-)


Daevid Vincent schreef:
I've had at least three job interviews in the past two weeks, and each one has asked me this rather "text book academic" question regarding the difference between "abstract" vs. "interface". I've been coding for nearly 20 years, and at least 10 of those have been in PHP and another 3 in J++. I have NEVER used either of these concepts/keywords? Am I missing some exciting tool/feature? All the reading I've done tonight just reinforces my thoughts that these are, for the most part useless. Unless you're building some HUGE project that has an API and there are teams of people that are going to extend your framework, then what good are they? This DB wrapper is the closest to an answer I've come across.
http://www.developer.com/lang/php/article.php/3604111

But that still doesn't explain the difference between abstract and interface, 
it only illustrates the possible need for a 'template' so others know which 
methods they must implement. In my mind, it just seems like overhead, as if you 
were going to write another DB wrapper using this one, then wouldn't you just 
look at their code (example) and implement those same methods anyways? I mean, 
you'd have to look at the abstract/interface to find out the required methods, 
so why not skip that and just look at the actual class instead?

Here are two more pages that still don't seem to answer why there are both and 
when you'd use one over the other?

http://www.hiteshagrawal.com/php/oops-in-php5/oops-in-php5-tutorial-abstract-class
http://www.hiteshagrawal.com/php/oops-in-php5/oops-in-php5-using-interface

And then this completely absurd over the top use of them for a HelloWorld 
example, which seems to use them just for the sake of using them...

http://marc.info/?l=php-general&m=115950654928311&w=2

Lastly was this page:

http://www.phpro.org/tutorials/Object-Oriented-Programming-with-PHP.html

Which seems to only really provide a "hack" (printerFax) to circumvent the lack 
of multiple inheritance.


Can someone clear this up for me?

Daevid.
http://daevid.com




--- End Message ---
--- Begin Message ---
> >> All that extra code for absolutely no benefit! It is 
> possible to define an
> >> interface (as in API) without actually using the term 
> "interface", so IMHO
> >> the term "interface" is totally redundant and a waste of time.
> >
> > While I agree that Interfaces are mostly a lot of extra 
> code, I have to
> > also say that they are there primarily to enforce a 
> contract between the
> > user of the interface and their classes that claim to implement the
> > interface. If someone creates a class that "Implements" an 
> interface,
> > then when I have to go edit or use the class, it had better 
> damn well
> > implement what it says it does :)
> 
> "enforcing a contract" is a lot of maningless gobbledegook. 
> The simple fact 
> is that it is possible to have an interface without ever 
> using the term 
> "interface". Nothing extra is added by using the term 
> "interface" (except 
> for effort) so there is absolutely no advantage in doing so. 
> That is why I 
> say that the term "interface" is a waste of effort as 
> absolutely nothng is 
> gained.

So if the only real benefit is to be some kind of required template for methods 
in 'extended' classes, why wasn't it "implemented" (excuse the pun) to be 
something like this (with interface as a keyword like abstract is or final or 
static):

class Template 
{
    private $vars = array();

    interface public function setVariable($name, $var)
    {
        $this->vars[$name] = $var;
    }

    interface public function getHtml($template)
    {
        foreach($this->vars as $name => $value) {
            $template = str_replace('{' . $name . '}', $value, $template);
        }

        return $template;
    }

    interface public function notYetCreatedMethod($foo) {}

    interface public function notYetCreatedMethod2($bar) 
    {
        return true;
    }

    public function someNotRequiredMethod ($fee)
    {
        return $fee + $fo;
    }
}

So now it would seem that the four methods are 'required' to be in extension 
classes and can be defined or not defined just like an abstract class right? I 
have to agree with Tony. This whole "interface" business just seems redundant 
and a waste of code.


--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 9:13 PM, Daevid Vincent <[EMAIL PROTECTED]> wrote:

> > >> All that extra code for absolutely no benefit! It is
> > possible to define an
> > >> interface (as in API) without actually using the term
> > "interface", so IMHO
> > >> the term "interface" is totally redundant and a waste of time.
> > >
> > > While I agree that Interfaces are mostly a lot of extra
> > code, I have to
> > > also say that they are there primarily to enforce a
> > contract between the
> > > user of the interface and their classes that claim to implement the
> > > interface. If someone creates a class that "Implements" an
> > interface,
> > > then when I have to go edit or use the class, it had better
> > damn well
> > > implement what it says it does :)
> >
> > "enforcing a contract" is a lot of maningless gobbledegook.
> > The simple fact
> > is that it is possible to have an interface without ever
> > using the term
> > "interface". Nothing extra is added by using the term
> > "interface" (except
> > for effort) so there is absolutely no advantage in doing so.
> > That is why I
> > say that the term "interface" is a waste of effort as
> > absolutely nothng is
> > gained.
>
> So if the only real benefit is to be some kind of required template for
> methods in 'extended' classes, why wasn't it "implemented" (excuse the pun)
> to be something like this (with interface as a keyword like abstract is or
> final or static):
>
> class Template
> {
>    private $vars = array();
>
>    interface public function setVariable($name, $var)
>    {
>        $this->vars[$name] = $var;
>    }
>
>    interface public function getHtml($template)
>     {
>        foreach($this->vars as $name => $value) {
>            $template = str_replace('{' . $name . '}', $value, $template);
>        }
>
>        return $template;
>    }
>
>     interface public function notYetCreatedMethod($foo) {}
>
>    interface public function notYetCreatedMethod2($bar)
>    {
>        return true;
>    }
>
>    public function someNotRequiredMethod ($fee)
>    {
>        return $fee + $fo;
>    }
> }
>
> So now it would seem that the four methods are 'required' to be in
> extension classes and can be defined or not defined just like an abstract
> class right?


right, just like an abstract class; not like an interface. heres where it
shys away from the interface concept,

   interface public function setVariable($name, $var)
   {
       $this->vars[$name] = $var;
   }

youve specified a concrete method here; thats not allowed in an interface.
if you want to do it w/ an abstract class, this is how you do it.

abstract class Silly {
  abstract function a() {}
  abstract function b() {}
}

does that make sense?  great, so how do we use it;

abstract class Cool extends Silly {
  function a() { // define behavior }
  function b() { // define behavior }
}

damn!  we just threw away our 1 chance to extend something on the Cool
class; and i thought it was supposed to be cool!  the whole problem is, php
is a single inheritance language.  that means you cannot extend classes more
than once.  therefore, using the extends keyword on a class is :read a BFD.
so how do we handle multiple inheritance in a single inheritance language?
simple (ive posted this before, but f-it; if dupes are common place then so
be it) by using composition.

so to try and keep it brief:

interface A { function a() }
interface B { function b() }

interface AImpl { function a() { // standard concrete implementation } }
interface BImpl { function b() { // standard concrete implementation } }

class C function c() { // do concrete stuff here }

class D extends C implements A, B {
  $a = null; $b = null;
  function __construct() {
    $a = new AImpl();
    $b = new BImpl();.
  }

  function a() { // do standard concrete A stuff via delegation
    return $this->a->a();
  }

  function b() { // do standard concrete B stuff via delegation
    return $this->b->b();
 }
}

we do this is because we php doesnt support the following;

class D extends A, B, C { // you know  the rest }

could it be done w/o interfaces; of course.  but then it becomes difficult
to determine what the hell is going on.  why does D have a() and b() ??
because theres some client code out there that expects it.  better know
about that code otherwise youre SOL.  by using interfaces its clear when
reading this code, using this code or creating similar code that it *must*
have those methods because its obligated by claiming it implements the
interface.

I have to agree with Tony. This whole "interface" business just seems
> redundant and a waste of code.


well lets think about it.  what is polymorphism??? that means multiple
things support the same action; period.  so looking at an example w/o
interfaces, supposedly we wont have redundant code; lets zoom in on this
theory.

class A {
 function a() {}
 function b() {}
}

nice; i have a little class; it does 2 things.  so, i have some code that i
use to call it right, cause its really useful; lets take a look:

function doStuff($aThing) {
  $aThing->a();
  $aThing->b();
}

$a = new A();
doStuff($a);

now i want to build some more cool stuff, cause i just love programming
these awesome classes.  but i want to be smart about it; i dont want to
clutter up my doStuff method w/ some worthless conditionals, or switch code;
thats for old timers ;)  so ill try this out:

class B {
  function a() {}
  function b() {}
}

holy crap !! now i can use instances of the B class wherever i can use
instances of the A class and i dont even have to bother checking which type
of class the instance actually is :O  that *is* the advantage polymorphism
brings to the table.  so you tell me; have we duplicated anything in classes
A and B ??  looks like weve duplicated a() and b() in the instance methods.
if you ask me, thats the entire point.  to duplicate a set of methods, an
interface.  that is what polymorphism is all about.

all the interface construct is, is another step down this road:

interface IlearnedSomethingNewToday {
  function a()
  function b()
}

now A and B can both implement this interface and we can all go home early
because we didnt spend all day coming to the realization that A and B have a
common set of methods for a particular reason.  and we dont have to know
about doStuff() wanting to call all those methods either.  any client code
that works w/ IlearnedSomethingNewToday can rightfully expect support of
both a() and b().  but i ask you, is writing the interface any more
*duplication* than adding an additional class to the system (w/o interfaces)
?

class C {
  function a() {}
  function b() {}
}

no, its not.  does it clarify WTF is going on in the code for us; yes.  is
it faster than run time checks in userspace
eg.

function isIlearnedSomethingNewToday($instance) {
  if(is_object($instance) && is_method($instance, 'a') &&
is_method($instance, 'b')) { return true; }
  else { return false; }
}

yes.  and we know at compile time if new classes are missing methods theyre
supposed to have.  also, in php5 we can use type hinting as well:

function doStuff(IlearnedSomethingNewToday $aThing) { //...

and this is still just the tip of the iceberg; previously i thought php
didnt support interface inheritance, search the archives; last time around
in this conversation i lamented about it.  but in recent history (again in
the archives; i discovered this is supported).  so for example

interface A {
  function a()
}

interface B {
  function b()
}

interface C extends A, B {
  function c()
}

class D implements C {
  function a() {}
  function b() {}
  function c() {}
}

why would you want to do that?  the same reasons you would want multiple
inheritance in a class hierarchy.  interfaces are lightweight abstract
classes; they are entirely abstract; and they dont cost you an extends
keyword.  they are very powerful.

here is yet another common pitfall of inheritance alone

class Z {
  function a() {}
  function b() {}
  function c() {} // note use only in C subclass
}

specific methods for specific subclasses are disastrous.  interfaces to the
rescue:

class Z {
  function a() {}
  function b() {}
}

interface CStuff {
  function c() {}
}

for those of you who still doubt me i submit the following;
1. if interfaces are a useless waste of code duplication, then why have they
been ported to a number of languages, php included?
2. read the first chapter of Head First Design Patterns.  when you find out
how joe got burnt by inheritance, your perspective will be changed.

-nathan

--- End Message ---
--- Begin Message ---
Can anybody tell me what is the purpose of PHP_OUTPUT_HANDLER_START
(et al) so I can add a Note to the manual?

They aren't really explained anywhere I can find, and the source...

Well, it seems to be just |= PHP_OUTPUT_HANDLER_START when the first
handler starts and then I kinda get lost as to what's going on...

-- 
Can you do me a favor?
Sign up for http://Facebook.com
Add http://apps.facebook.com/whereivebeen/
Review it, and let 'em know Rich sent you.
http://www.facebook.com/apps/application.php?id=2603626322
(Scroll down to the middle of the middle column)
Give it a 5-star rating please :-)
(If you can't go 5-star, email me to tell me why)


--- End Message ---
--- Begin Message ---
On Wed, 16 Apr 2008 13:26:09 -0500, Javier Huerta wrote:
>>>""Daniel Brown"" <[EMAIL PROTECTED]> wrote:
>>
>>> Is there a reverved variable that can be used to check
>>> the remote IP address of the computer hitting your web page?
>>
>> <?php
>> $_SERVER['REMOTE_ADDR'];
>> ?>
>
> Wow that was quick, thanks Daniel.

Reviewing what is at hand via 

        <?php phpinfo(); ?> 

                from time to time is useful.


--- End Message ---
--- Begin Message ---
all,

i have heard from various sources that using the & in php can at times be
costly, and therefore, it should not be used when it is not needed.  for
example, passing an array by reference because you think youre passing the
actual array is not a good idea.  only pass it by reference if a modified
version needs to be handed to the calling code via an actual parameter.
im also wondering about php4 code thats now running under 5; such as
function &returnObject() ...
$a =& new SomeClass() ...
lets suppose, for the sake of arguments, i have my hands on a codebase where
everything actually does count.  the code was php4 and is now transitioning
to 5.  does anybody know if there would be a performance gain in running the
whole thing through sed to try and strip out the unnecessary & characters ?
any empirical data?

thx,

-nathan

--- End Message ---
--- Begin Message ---
On Wed, 2008-04-16 at 23:37 -0400, Nathan Nobbe wrote:
> all,
> 
> i have heard from various sources that using the & in php can at times be
> costly, and therefore, it should not be used when it is not needed.  for
> example, passing an array by reference because you think youre passing the
> actual array is not a good idea.  only pass it by reference if a modified
> version needs to be handed to the calling code via an actual parameter.
> im also wondering about php4 code thats now running under 5; such as
> function &returnObject() ...
> $a =& new SomeClass() ...
> lets suppose, for the sake of arguments, i have my hands on a codebase where
> everything actually does count.  the code was php4 and is now transitioning
> to 5.  does anybody know if there would be a performance gain in running the
> whole thing through sed to try and strip out the unnecessary & characters ?
> any empirical data?

If it's faster, it's faster so that would suggest a performance gain...
but as many will tell you, and you most likely already know... is the
gain worth the effort? BTW, rote replacement of references like that,
may not be a good idea. There are times when you really do want a
reference to an object... or maybe not... but you or someone else might
have done it anyways ;)

Contrast:
<?php

    $b = new Foo();
    $a = &$b;
    $a = new Fee();

?>

Versus:
<?php

    $b = new Foo();
    $a = $b;
    $a new Fee();

?>

In the first $b references the instance of Fee since $a is a reference.
In the second, $b remains an instance of Foo when $a becomes and
instance of Fee.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


--- End Message ---
--- Begin Message ---
On Wed, Apr 16, 2008 at 4:04 AM, Waynn Lue <[EMAIL PROTECTED]> wrote:
> I'm using PHP to cache files that are backed by the database.  In the
>  course of writing these functions, I end up with a set of variables
>  that are needed by my application, returned in an array.  I can either
>  directly generate the array in a .php file, then use require_once to
>  get that variable, or I can use PHP serialization, write that array
>  out to a file, then in my application read the array in, deserialize,
>  etc.
>
>  I spent awhile trying to look at the performance of php serialization,
>  but except for one unsubstantiated comment on the php serialize() doc
>  page, I haven't found much.  Does anyone have any knowledge of that,
>  and also of the two approaches in general?  The pro of the
>  serialization is that I think it's slightly easier to write, but the
>  con is that it's harder to read.
>
>  Thanks!
>
>  --
>  PHP General Mailing List (http://www.php.net/)
>  To unsubscribe, visit: http://www.php.net/unsub.php
>
>

According to this
(http://us2.php.net/manual/en/function.var-export.php#76099),
serialize is faster than var_export.

-- 
-Casey

--- End Message ---
--- Begin Message ---
Hi all.

We have taken over a site and a problem we have is that French special
characters aren't displaying correctly, they are displaying a weird square
block.

I have checked the content type and it's as follows: 

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

I also notice that the "charset=iso-8859-1" is missing in the above meta
tag, could this be affecting the characters?

I have seen that there is no DOCTYPE declaration, could this be the problem
if this is omitted?

If you have any suggestions, please let me know.

TIA.

Angelo

Web: http://www.elemental.co.za 



--- End Message ---

Reply via email to