php-general Digest 3 Oct 2007 13:52:59 -0000 Issue 5052

Topics (messages 262663 through 262679):

Re: Good Regex for general text search
        262663 by: Amos Vryhof
        262664 by: Chris

Re: Custom pipe script failure code
        262665 by: Chris

Optimized PHP
        262666 by: ashish.sharma
        262667 by: Larry Garfield
        262668 by: Cameron Just
        262669 by: Zoltán Németh
        262675 by: Per Jessen
        262679 by: Nathan Nobbe

the opposite of a join?
        262670 by: jd.pillion.gmail.com
        262672 by: Zoltán Németh
        262673 by: TG
        262674 by: Satyam

Re: manipulating CSV files
        262671 by: pere roca
        262677 by: Wolf

Re: [PHP-DB] the opposite of a join?
        262676 by: Lasitha Alawatta

Re: Beginner Tutorials for using CLASSES in PHP4
        262678 by: Nathan Nobbe

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 ---
Ok, My example was pretty bad.

I was just looking for an easier/more optimal way to look for something
along the lines of
"word1*word2*word3*word4" rather than "word1 word2 word3 word4" as it
currently does.

Actually, I think I have an idea for a way to do what I want without a
regular expression.... I'll have to see how fast it is though before
actually using it.

Thanks anyway.

On 10/2/07, Chris <[EMAIL PROTECTED]> wrote:
>
> Amos Vryhof wrote:
> > I'm writing a few very simple search scripts.
> >
> > One searches in a few columns of a CSV file, while another just searches
> > through a collection of file names.
> >
> > Currently, I just have it stripping illegal characters from the "needle"
> > and "haystack" then doing a substring search
> >
> > if (substr_count(...)>0) {
> >    return formatted results....
> > }
> >
> > What I'm looking to do is enhance my searches with preg_match.  What I
> > want to do is take my needle and haystack with the illegal strings
> > stripped out, split it down to words, and search for the string, no
> > matter what is between the words.
> >
> > ex: "the cat and the dog"
> >
> > would also return
> >
> > "the cat ran from the bull and dog"
> >
> > I might learn Regular Expressions at some point in the future, but I
> > just haven't had time to yet... so what I need is just what I would use
> > to build my string pattern for preg_match... I'll figure out the rest
> > and change my scripts appropriately.
>
> You're not going to be able to do that with a regular expression because
> the order of the words isn't even the same.
>
> Why would you need to do this with a regex instead of the way it's
> working right now?
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
> _______________________________________________________________________
> This Email has been scanned for viruses by SkyScan.
>
>


-- 
-- 
Amos Vryhof
Assistant Web Developer
Holsteinworld.com
[EMAIL PROTECTED]
1-800-334-1904 Ext 239

--- End Message ---
--- Begin Message ---
Amos Vryhof wrote:
Ok, My example was pretty bad.

I was just looking for an easier/more optimal way to look for something
along the lines of
"word1*word2*word3*word4" rather than "word1 word2 word3 word4" as it
currently does.

Actually, I think I have an idea for a way to do what I want without a
regular expression.... I'll have to see how fast it is though before
actually using it.

Not guaranteed to work at all but if you really want to use a regex you could do something like this:


$words = array('word1', 'word2', 'word3');

$search = '%';
foreach ($words as $word) {
  $search .= '\\\b'.preg_quote($word, '%') . '\\\b.*?';
}
$search .= '%is';

preg_match($search, $string, $found_matches);


So you should end up with something like:

preg_match('%\bword1\b.*?\bword2\b.*?\bword3\b%is', $string, $found_matches);


See http://www.php.net/preg_quote and http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php and http://www.php.net/manual/en/reference.pcre.pattern.syntax.php

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

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

So is there a way to exit(); with some sort of code to put that message back into the queue? I have read that I need to exit(75); but that does not work. If anyone could help, that would be more than fantastic.

That's exactly what you need. What doesn't work exactly?

$ php -a
Interactive mode enabled

<?php
echo "Exit code should be 75\n";
exit(75);
Exit code should be 75
$ echo $?
75

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

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

I am working on PHP from quite some time. I am pretty much comfortable in
writing PHP code but I always want that I should write good, quality code.
For this I always look for the best practices which other developers uses
and implement and I am writing this for the same reason as I would like to
know how can i code a good, optimized PHP code. What are the areas where I
can optimize my code more to avoid extra consumption of resources h/w or
s/w. What are the best practices I can follow to optimize my code to
increase the speed and performance of my application and to reduce down the
memory consumption. For example ..

In an application where I am having some different settings for each of the
user/visitor, then what will be the best approach of doing this? Should I
keep all the settings in sessions or should i create an xml/ini file for
each user and call that in the bootstrap file (at runtime, on the basis of
the the User) to pick the settings of that user.

These are the kind of questions for which I always have to think. So, can
anyone suggest me some source / article / reference from where I can find
the solutions of such of my problems.

Looking forward for your suggestions ..

Thx to all ..

Ashish
-- 
View this message in context: 
http://www.nabble.com/Optimized-PHP-tf4559881.html#a13013016
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
First rule: Premature optimization is the root of all evil.  Don't try to 
squeeze every millisecond out of your code unless it really needs it.  

That said, the conventional place to stick user account data is in the 
database.  The exact schema will vary, but you will want some sort of unique 
user id, a login name, a password, and "other stuff".  

For tracking active visitors, that's what the session is for.  Only store 
information in the session that should be persistent only for one visit.  
That will probably include the active user id plus whatever else you need.  

You also probably don't want to use the default session save handling, as it 
is not very robust.  Instead, write your own session handling functions and 
save the session data to the database.  That will give you better security, a 
more robust and extensible system, and in some cases even a performance 
boost.  See:

http://www.php.net/manual/en/function.session-set-save-handler.php

On Wednesday 03 October 2007, ashish.sharma wrote:
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish


-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

--- End Message ---
--- Begin Message --- One trick that one of my friends has taught me is to only use double quotes "s where needed as they are parsed by PHP and instead use single quotes 's

i.e.
$fred['john'] = 10;
is better than
$fred["john"] = 10;

or
echo 'This is some text' . "\n";
instead of
echo "This is some text\n";

He told me that everything within double quotes must be walked through by PHP looking for variables or other escaped characters. Since most code has these style statements every few lines the overall time saved adds up.

ashish.sharma wrote:
Hello All,

I am working on PHP from quite some time. I am pretty much comfortable in
writing PHP code but I always want that I should write good, quality code.
For this I always look for the best practices which other developers uses
and implement and I am writing this for the same reason as I would like to
know how can i code a good, optimized PHP code. What are the areas where I
can optimize my code more to avoid extra consumption of resources h/w or
s/w. What are the best practices I can follow to optimize my code to
increase the speed and performance of my application and to reduce down the
memory consumption. For example ..

In an application where I am having some different settings for each of the
user/visitor, then what will be the best approach of doing this? Should I
keep all the settings in sessions or should i create an xml/ini file for
each user and call that in the bootstrap file (at runtime, on the basis of
the the User) to pick the settings of that user.

These are the kind of questions for which I always have to think. So, can
anyone suggest me some source / article / reference from where I can find
the solutions of such of my problems.

Looking forward for your suggestions ..

Thx to all ..

Ashish

--- End Message ---
--- Begin Message ---
2007. 10. 3, szerda keltezéssel 16.07-kor Cameron Just ezt írta:
> One trick that one of my friends has taught me is to only use double 
> quotes "s where needed as they are parsed by PHP and instead use single 
> quotes 's
> 
> i.e.
> $fred['john'] = 10;
> is better than
> $fred["john"] = 10;
> 
> or
> echo 'This is some text' . "\n";
> instead of
> echo "This is some text\n";
> 
> He told me that everything within double quotes must be walked through 
> by PHP looking for variables or other escaped characters. Since most 
> code has these style statements every few lines the overall time saved 
> adds up.
> 

AFAIK that's not absolutely true.
First, every string must be checked over for escaped characters and such
- not only those within double quotes.
Second, the opcode for double quotes differ only if they contain
variables:
http://blog.libssh2.org/index.php?/archives/28-How-long-is-a-piece-of-string.html

and anyway, the microseconds you could win with this really don't count
that much to be worth the effort... find real bottlenecks and optimize
against those.

greets
Zoltán Németh

> ashish.sharma wrote:
> > Hello All,
> >
> > I am working on PHP from quite some time. I am pretty much comfortable in
> > writing PHP code but I always want that I should write good, quality code.
> > For this I always look for the best practices which other developers uses
> > and implement and I am writing this for the same reason as I would like to
> > know how can i code a good, optimized PHP code. What are the areas where I
> > can optimize my code more to avoid extra consumption of resources h/w or
> > s/w. What are the best practices I can follow to optimize my code to
> > increase the speed and performance of my application and to reduce down the
> > memory consumption. For example ..
> >
> > In an application where I am having some different settings for each of the
> > user/visitor, then what will be the best approach of doing this? Should I
> > keep all the settings in sessions or should i create an xml/ini file for
> > each user and call that in the bootstrap file (at runtime, on the basis of
> > the the User) to pick the settings of that user.
> >
> > These are the kind of questions for which I always have to think. So, can
> > anyone suggest me some source / article / reference from where I can find
> > the solutions of such of my problems.
> >
> > Looking forward for your suggestions ..
> >
> > Thx to all ..
> >
> > Ashish
> >   
> 

--- End Message ---
--- Begin Message ---
Zoltán Németh wrote:

> and anyway, the microseconds you could win with this really don't
> count that much to be worth the effort... find real bottlenecks and
> optimize against those.

And finally, if you're worried about microseconds, why are you using an
interpreted language? 


/Per Jessen, Zürich

--- End Message ---
--- Begin Message ---
On 10/3/07, ashish.sharma <[EMAIL PROTECTED]> wrote:
>
>
> Hello All,
>
> I am working on PHP from quite some time. I am pretty much comfortable in
> writing PHP code but I always want that I should write good, quality code.
> For this I always look for the best practices which other developers uses
> and implement and I am writing this for the same reason as I would like to
> know how can i code a good, optimized PHP code. What are the areas where I
> can optimize my code more to avoid extra consumption of resources h/w or
> s/w. What are the best practices I can follow to optimize my code to
> increase the speed and performance of my application and to reduce down
> the
> memory consumption. For example ..
>
> In an application where I am having some different settings for each of
> the
> user/visitor, then what will be the best approach of doing this? Should I
> keep all the settings in sessions or should i create an xml/ini file for
> each user and call that in the bootstrap file (at runtime, on the basis of
> the the User) to pick the settings of that user.
>
> These are the kind of questions for which I always have to think. So, can
> anyone suggest me some source / article / reference from where I can find
> the solutions of such of my problems.
>
> Looking forward for your suggestions ..
>
> Thx to all ..
>
> Ashish
> --
> View this message in context:
> http://www.nabble.com/Optimized-PHP-tf4559881.html#a13013016
> Sent from the PHP - General mailing list archive at Nabble.com.
>


one nice trick you can easily implement is to compress your code before
pushing it to production.
the php cli exposes a method for stripping out the whitespace and comments.

php -w

-nathan

--- End Message ---
--- Begin Message ---
I have a company table and a contacts table.  In the contacts table, there
is a field called "companyID" which is a link to a row in the company table.

 

What is the easiest way to query the company table for all the company rows
whose ID is NOT linked to in the contact table? Basically, the opposite of a
join?

 

Thanks

 

J

 


--- End Message ---
--- Begin Message ---
2007. 10. 3, szerda keltezéssel 05.21-kor [EMAIL PROTECTED] ezt írta:
> I have a company table and a contacts table.  In the contacts table, there
> is a field called "companyID" which is a link to a row in the company table.
> 
>  
> 
> What is the easiest way to query the company table for all the company rows
> whose ID is NOT linked to in the contact table? Basically, the opposite of a
> join?
> 

maybe something like

SELECT * FROM company WHERE (SELECT COUNT(*) FROM contact WHERE
company_id = company.company_id)=0

it's not very efficient, but I don't have any better idea. someone else?

greets
Zoltán Németh

>  
> 
> Thanks
> 
>  
> 
> J
> 
>  
> 

--- End Message ---
--- Begin Message ---
Actually you still want to use a join, just an OUTER join instead of an INNER 
one.

With an OUTER join, you can get all the rows that match as well as rows where 
it doesn't match:

http://en.wikipedia.org/wiki/Join_(SQL)#Left_outer_join

In the example there, DepartmentID 36 is present in the `Employee` table but 
not in the `Department` table so you get NULL for the `Department` data.

Then it's just a matter of checking for NULL.    Remember that you can't do 
"WHERE DepartmentID = NULL" because that will always end up being TRUE 
(can't use regular comparisons with NULL), you have to use "WHERE 
DepartmentID IS NULL".

-TG



----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>, <[EMAIL PROTECTED]>
Date: Wed, 3 Oct 2007 05:21:06 -0500
Subject: [PHP] the opposite of a join?

> I have a company table and a contacts table.  In the contacts table, there
> is a field called "companyID" which is a link to a row in the company table.
> 
>  
> 
> What is the easiest way to query the company table for all the company rows
> whose ID is NOT linked to in the contact table? Basically, the opposite of a
> join?
> 
>  
> 
> Thanks
> 
>  
> 
> J
> 
>  
> 
> 
> 

--- End Message ---
--- Begin Message --- ----- Original Message ----- From: "Zoltán Németh" <[EMAIL PROTECTED]>

it's not very efficient, but I don't have any better idea. someone else?


Indeed, that sort of query is one of the worst and there is little you can do to improve it save making sure you have an index on the field of the table pointed at, even if you create it for this query and drop it once done.

greets
Zoltán Németh



Thanks



J




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



--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.13.39/1045 - Release Date: 02/10/2007 18:43



--- End Message ---
--- Begin Message ---
  hi Wolf and Jim, thanks for the answer!  Very useful.
  Now  It would be wondeful if I can pick up the values from a CSV file
(coordinates) and apply a postGIS/postgreSQL function (Select ...) to this
data and add the resulting values as a new filed in the CSV !

  Is that possible?

  Thanks,
  Pere

Wolf-6 wrote:
> 
> /////////////////////////
>  $filename=""; // Name of your CSV file
>  $file_path = ""; // whatever your files are pathed
>  $filename = $file_path.$filename;
>  $handle = @fopen($filename, "r");
>  $k=0;
>  $entry = $file_path . "entry_file.txt"; // I use this to make a new entry
> file
>  $entry_file = fopen($entry, 'w');
>  $file_data = "dummy";
>  if (!$entry_file){die("Unable to open $entry_file");}
>  if ($handle)
>  {
>   echo "$filename opened successfully!<BR>";
>   flush();
>   while (!feof($handle)) 
>   {
>    $file_date = $name;  // use this for adding the name for each one
>    $file_data .= fgets($handle, 4096);
>    fwrite($entry_file, $file_data);
>    echo "$file_data written to $entry";
>    flush();
>   }
>  }
>  fclose($handle);
>  fclose($entry_file);
> }
> else
> { die("Error opening $filename"); }
> 
> /////////////////////////
> 
> 
> ---- pere roca <[EMAIL PROTECTED]> wrote: 
>> 
>>   hi folks,
>>   
>>   I have a CSV file. Data is separated by ','. For example:
>>   -94.86524,42.059444,A,B,X
>>   -96.86524,42.059444,A,B,Y1
>>   -99.86524,42.059444,A,B,C1 
>> 
>>   I want to interactively insert the user_name (passed by a php variable)
>> into the first "field" to insert then on my DataBase. 
>> 
>>   Peter,-94.86524,42.059444,A,B,X
>>   Jan,-96.86524,42.059444,A,B,Y1
>>   ...
>>   I know there is a command (fwrite) to write, but I can't figure out how
>> to
>> start with it... 
>>   Afet open csv, etc. I think I should first check when there is a
>> "return"
>> (we change of file), then I add the "user_name" parameter and repeat it
>> as
>> long as there is some record.  
>>   
>>   Any workaround or code doing something similar for a newbie in php,
>> please?
>>   Thanks,
>> 
>>    Pere
>> -- 
>> View this message in context:
>> http://www.nabble.com/manipulating-CSV-files-tf4548721.html#a12980387
>> 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/manipulating-CSV-files-tf4548721.html#a13016318
Sent from the PHP - General mailing list archive at Nabble.com.

--- End Message ---
--- Begin Message ---
Sure, just use the code I/we provided as the basis for what you need.

When you get stuck, post your code and we'll be happy to look at it for you.

Wolf

---- pere roca <[EMAIL PROTECTED]> wrote: 
> 
>   hi Wolf and Jim, thanks for the answer!  Very useful.
>   Now  It would be wondeful if I can pick up the values from a CSV file
> (coordinates) and apply a postGIS/postgreSQL function (Select ...) to this
> data and add the resulting values as a new filed in the CSV !
> 
>   Is that possible?
> 
>   Thanks,
>   Pere
> 
> Wolf-6 wrote:
> > 
> > /////////////////////////
> >  $filename=""; // Name of your CSV file
> >  $file_path = ""; // whatever your files are pathed
> >  $filename = $file_path.$filename;
> >  $handle = @fopen($filename, "r");
> >  $k=0;
> >  $entry = $file_path . "entry_file.txt"; // I use this to make a new entry
> > file
> >  $entry_file = fopen($entry, 'w');
> >  $file_data = "dummy";
> >  if (!$entry_file){die("Unable to open $entry_file");}
> >  if ($handle)
> >  {
> >   echo "$filename opened successfully!<BR>";
> >   flush();
> >   while (!feof($handle)) 
> >   {
> >    $file_date = $name;  // use this for adding the name for each one
> >    $file_data .= fgets($handle, 4096);
> >    fwrite($entry_file, $file_data);
> >    echo "$file_data written to $entry";
> >    flush();
> >   }
> >  }
> >  fclose($handle);
> >  fclose($entry_file);
> > }
> > else
> > { die("Error opening $filename"); }
> > 
> > /////////////////////////
> > 
> > 
> > ---- pere roca <[EMAIL PROTECTED]> wrote: 
> >> 
> >>   hi folks,
> >>   
> >>   I have a CSV file. Data is separated by ','. For example:
> >>   -94.86524,42.059444,A,B,X
> >>   -96.86524,42.059444,A,B,Y1
> >>   -99.86524,42.059444,A,B,C1 
> >> 
> >>   I want to interactively insert the user_name (passed by a php variable)
> >> into the first "field" to insert then on my DataBase. 
> >> 
> >>   Peter,-94.86524,42.059444,A,B,X
> >>   Jan,-96.86524,42.059444,A,B,Y1
> >>   ...
> >>   I know there is a command (fwrite) to write, but I can't figure out how
> >> to
> >> start with it... 
> >>   Afet open csv, etc. I think I should first check when there is a
> >> "return"
> >> (we change of file), then I add the "user_name" parameter and repeat it
> >> as
> >> long as there is some record.  
> >>   
> >>   Any workaround or code doing something similar for a newbie in php,
> >> please?
> >>   Thanks,
> >> 
> >>    Pere
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/manipulating-CSV-files-tf4548721.html#a12980387
> >> 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/manipulating-CSV-files-tf4548721.html#a13016318
> 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 ---
Hi J, 


Checkout this,


SELECT * FROM tbl_company where id not in (SELECT companyID from
tbl_contacts)






Regards,
Lasitha Alawatta
Application Developer
Destinations of the World Holding Establishment
P O Box: 19950
Dubai, United Arab Emirates
( Ph +971 4 295 8510 (Board) / 1464 (Ext.)
7 Fax +971 4 295 8910
+ [EMAIL PROTECTED] 

-----Original Message-----
From: John Pillion [mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, October 03, 2007 2:21 PM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: [PHP-DB] the opposite of a join?

I have a company table and a contacts table.  In the contacts table,
there
is a field called "companyID" which is a link to a row in the company
table.

 

What is the easiest way to query the company table for all the company
rows
whose ID is NOT linked to in the contact table? Basically, the opposite
of a
join?

 

Thanks

 

J

 

DOTW DISCLAIMER:

This e-mail and any attachments are strictly confidential and intended for the 
addressee only. If you are not the named addressee you must not disclose, copy 
or take
any action in reliance of this transmission and you should notify us as soon as 
possible. If you have received it in error, please contact the message sender 
immediately.
This e-mail and any attachments are believed to be free from viruses but it is 
your responsibility to carry out all necessary virus checks and DOTW accepts no 
liability
in connection therewith. 

This e-mail and all other electronic (including voice) communications from the 
sender's company are for informational purposes only.  No such communication is 
intended
by the sender to constitute either an electronic record or an electronic 
signature or to constitute any agreement by the sender to conduct a transaction 
by electronic means.


--- End Message ---
--- Begin Message ---
there is no way to create an abstract class in php4.
in an abstract class definition subclasses are forced to implement those
methods
that have been declared abstract.  or they are allowed to declare the method
as abstract themselves and force their children to provide a concrete
definition.
the only way to achieve this in php4 is to have an essentially empty
definition in a
class and through external documentation or communication w/ other
developers,
indicate the function need be overridden to be usable.
communicating externally, something that could be communicated inside the
language
itself is very delicate, one that would not do well in a scenario with a
large
number of developers.

interfaces introduce the concept of design-by-contract.  they are very
powerful because
they give code another avenue to be polymorphic.  inheritance is often
overused because
people dont understand the power of composition and the benefit of
interfaces to facilitate
composition.

for people coming to php4 from languages like java, or even .net; anything
that
implements proper access control mechanisms, abstract classes and
interfaces; those
people may be able to design systems w/ php4 that are properly structured.
starting out w/
php4 and trying to learn oop will likely lead individuals into bad practices
that they cannot foresee
until years down the road, when their systems are growing at a slow rate and
they have to
figure out why or somebody who understands oop comes in and explains where
the problems are.

the most common mistake i encounter with oop php4 is accessing class member
functions directly.
this is a complete violation of encapsulation and php4 provides no way to
enforce it.
yes, php4 does provide some of the fundamental oop facilities and its all
the community had for a while.
the bottom line is the facilities it offers for oop are bare and i see no
reason to try to understand its
peculiarities and weaknesses when php5 is here and php6 is on the way.

-nathan

On 10/2/07, Tony Marston <[EMAIL PROTECTED]> wrote:
>
>
> ""Nathan Nobbe"" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > although some people believe differently than i; i would argue
> > trying to learn how to design w/ the classes that php4 provides
> > is a waste of time.
>
> I disagree. PHP 4 gives you access to classes, encapsulation, inheriance
> and
> polymorphism. This is all you need for OO programming. All that extra crap
> in PHP 5 is just window dressing.
>
> >  most books you will find regarding object oriented
> > design assume the language has the basic constructs.  ppp mainly.
> > also, there are other important facilities php4 lacks like abstract
> > classes
>
> You can write abstact classses in PHP 4, it's just that you can't use the
> word "abstract". Interfaces are totally irrelevant as any method can be
> accessed directly through its function definition.
>
> > and interfaces, not to mention you have to explicitly assign objects by
> > reference in php4. (if you dont want a copy created).
> > unless you are bound to php4 by work or something
> > i suggest you start working w/ php5.  also, if your looking for some
> > design
> > techniques i recommend studying design patterns.
>
> Design patterns are overrated. For building transactions in CRUD
> applications you need transaction patterns.
>
> --
> Tony Marston
> http://www.tonymarston.net
> http://www.radicore.org
>
> >  the heads first book
> > is a great starting point.
> > actually if you want a solid reference thats free on the web look at
> > phpPatterns <http://www.phppatterns.com/docs/start>
> > the code is mostly php4 i believe.
> >
> > -nathan
> >
> >
> > On 9/29/07, Jeff Cohan <[EMAIL PROTECTED]> wrote:
> >>
> >> Yes, I know how to Google, and I've been Googling...
> >>
> >> But I would appreciate advice about good beginner tutorials using
> >> classes in PHP4 based on your actual experiences. I.e., have some of
> >> you found tutorials that really unlocked the doors for you?
> >>
> >> Ideally, such tutorials would have somewhat realistic examples. (I
> >> already know how to output "Hello, World" using a class, and I tend
> >> to find examples like those unhelpful. Maybe it's just me.)
> >>
> >> My main challenge is modularizing yer basic BREAD/CRUD operations
> >> with MySQL databases.
> >>
> >> I've made some strides in creating increasingly modular functions to
> >> present browse lists, edit forms and add forms; to perform
> >> field-level and form-level validations; and to perform inserts,
> >> updates and deletes. My approach is to utilize multidimensional
> >> arrays which define the column names, column labels (for forms),
> >> form control types (input, select, checkbox, etc.) and other
> >> attributes of the form controls. I've got a "library" of validation
> >> routines with error messages that appear on the form under the
> >> culprit form control.
> >>
> >> But I think taking the next step to use classes is going to make my
> >> life much easier.
> >>
> >> TIA for any guidance you might be able to offer.
> >>
> >> Jeff
> >>
> >> --
> >> 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
>
>

--- End Message ---

Reply via email to