Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Nathan Nobbe
On 9/30/07, 潘志彬 <[EMAIL PROTECTED]> wrote:
>
> $dbh = 'test';
>
> class search_helper extends AjaxACApplication
> {
> /**
>  * Database connection details
>  */
>
>// announce global variable before use it
>global $dbh;
>
> $db_hostname = $dbh;



global variables inside a class ??
as Martin said this is a bad practice.
if you were going to use a global variable inside a class, why bother w/
a class in the first place?
the point is to encapsulate, ie. hide implementation details from the user.
by relying on a global variable, the class is open to behavior modification
by
external code that does not have to go through its well-defined public
interface
to do so.  thats why its a bad practice.

-nathan


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Nathan Nobbe
painfully i find myself bound to it at my current job.  there ive been able
to
realize that proper oop can be used to an amazing extent in php4, however
altogether i wish we could just move on to 5 and i could stop writing in
// private
as a comment :)

-nathan

On 9/30/07, Jeff Cohan <[EMAIL PROTECTED]> wrote:
>
> Nathan Nobbe wrote:
> >
> > 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.  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
> > 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.  the heads first book
> > is a great starting point.
> > actually if you want a solid reference thats free on the web look at
> > phpPatterns 
> > the code is mostly php4 i believe.
> >
> > -nathan
>
> Thanks, Nathan. I have been moving toward the conclusion you suggest
> (i.e., don't bother with OOP in php4). Yes, I'm bound to php4
> currently.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Classes and access to outside variables

2007-09-29 Thread 潘志彬
$dbh = 'test';

class search_helper extends AjaxACApplication
{
/**
 * Database connection details
 */

   // announce global variable before use it
   global $dbh;

$db_hostname = $dbh;


   ...

Regards,
Ryu



2007/9/29, Merlin <[EMAIL PROTECTED]>:
>
> Hi there,
>
> I am new to PHP classes and I do want to access a variable outside the
> class, but somehow that does not work. global also does not have any
> effect.
>
> In the following example I would like to be able to access $dbh from
> inside the class like I did in that example. This does not work. Can
> somebody please give me a hint on the right syntax?
>
> $dbh = 'test';
>
> class search_helper extends AjaxACApplication
> {
> /**
>  * Database connection details
>  */
>
> var $db_hostname = $dbh;
>
> Thank you for any help,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Jeff Cohan
Nathan Nobbe wrote:
> 
> 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.  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
> 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.  the heads first book
> is a great starting point.
> actually if you want a solid reference thats free on the web look at
> phpPatterns 
> the code is mostly php4 i believe.
> 
> -nathan

Thanks, Nathan. I have been moving toward the conclusion you suggest
(i.e., don't bother with OOP in php4). Yes, I'm bound to php4
currently.

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



Re: [PHP] counting with leading zeros

2007-09-29 Thread brian

tedd wrote:

At 8:30 PM -0400 9/27/07, brian wrote:


I wasn't bitching! And i *thought* that my numerous attempts at
explaining such would have been enough. Obviously not, but wtf can you
do with people who seem to want only to stir up shit?


It sure sounded like you were bitching.


Gee, thanks for pointing that out, Jeeves. I'd say it's pretty damned 
obvious now that Rob thought i was bitching about his response to my 
query. However, if you'd have bothered to note my replies since, you 
might have twigged to the fact that i'd been trying to set that 
straight. But you just *had* to send off your own dickish response.


And, your off-list "fuck you, too, asswipe" to me certainly seems to 
support that -- don't you think?


How so? Had it crossed your little mind that maybe--just maybe--i was 
becoming not a little frustrated with the fact that my reply had been 
taken the wrong way? That, instead of accepting that and moving on, this 
had become far too OT with bullshit comments such as yours? So, yeah, 
you might say that i'm bitching *now*.


You and i have had our run-ins on this list on more than one occasion. 
Until now, i've chosen to take your crap in stride. If you have nothing 
constructive to add then STFU.


Look, there's nothing you can say to me that hasn't been said before 
(some of it deserving), so my advice is for you to refrain from such 
conduct and at least try to look professional. That way you'll hide your 
ignorance a little longer -- it's always worked for me.


This is me laughing. I'm sure you have no bloody idea how funny that 
statement looks from where i'm sitting. See the paragraph above.



Dan Parry wrote:

Can I please interject and say that I vastly respect Tedd(ddd) and Rob(bb?)
and their opinions



It's not so much that i disrespect Rob. It's just that i felt i had to 
call him out for being a dickhead by taking my statement out of context.


Tedd ... not so very much at all.

Robert Cummings wrote:
> On Fri, 2007-09-28 at 12:05 -0400, tedd wrote:
>
At 10:39 PM -0400 9/26/07, brian wrote:

>>>fuck you, too, asswipe
>
> Seems to be, an extra, comma, in the phrase. It reads, like Captain
> Kirk, saying, it.
>

Funny. Reminds of a Capt. Kirk quote:
"No more blah, blah, blah!"

brian

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Nathan Nobbe
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.  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
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.  the heads first book
is a great starting point.
actually if you want a solid reference thats free on the web look at
phpPatterns 
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
>
>


Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Jeff Cohan
Instruct ICC wrote:
> > From: [EMAIL PROTECTED]
> > Today's post was
> > prompted by my desire to prototype yet another suite of
> > browse-read-edit-add-delete functions for someone.
> 
> I was just going to ask you what is BREAD.  Cool, basically a 
> Web-based CRUD?  I can't find anything on it, can you point 
> me to some sites?

Being a carbo-freak, I just prefer the BREAD acronym to CRUD. I
think I found the BREAD reference first in Wikipedia. (I know, I
know...)

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



RE: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Instruct ICC

> From: [EMAIL PROTECTED]
> Today's post was
> prompted by my desire to prototype yet another suite of
> browse-read-edit-add-delete functions for someone.

I was just going to ask you what is BREAD.  Cool, basically a Web-based CRUD?  
I can't find anything on it, can you point me to some sites?

_
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx

Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Jeff Cohan
Greg -

Greg Maruszeczka wrote:
> Jeff:
> The following books really helped me get my head around basic 
> OOP and design patterns in PHP, especially the first one 
> which directly addresses both PHP4 and PHP5:
> 
> 1. PHP Architect's Guide to PHP Design Patterns, Jason E. 
> Sweat, PHP Architect Nanobooks, 2005
> 2. PHP 5 Objects, Patterns and Practice, Matt Zandstra, 
> Apress, 2004
> 
> It also seems like you might be wanting some direction on 
> things like ORM and database abstraction. Have you looked into 
> what some of the PHP-based frameworks are doing in this regard? 
> I know they're PHP5-only but studying projects like Symfony 
> and the new Zend Framework have really helped my understanding 
> quite a bit.
> Of course, the usual disclaimers apply.
> HTH,
> GM
> Greg Maruszeczka
> Websage Solutions
> http://websage.ca
> skype: websage.ca

Thanks very much for the reply and suggestions. My local B&N just
set aside their last copy of Jason Sweat's book for me to pick up.

As for database abstraction and frameworks, well... that's a big
"maybe" for me right now. Maybe later.

My main goal is to write smarter code that I can (a) find quickly
when I need to fix something and (2) re-use. Today's post was
prompted by my desire to prototype yet another suite of
browse-read-edit-add-delete functions for someone.

Best regards,
JC

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



Re: [PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Greg Maruszeczka
Jeff Cohan 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
>


Jeff:

The following books really helped me get my head around basic OOP and
design patterns in PHP, especially the first one which directly
addresses both PHP4 and PHP5:

1. PHP Architect's Guide to PHP Design Patterns, Jason E. Sweat, PHP
Architect Nanobooks, 2005
2. PHP 5 Objects, Patterns and Practice, Matt Zandstra, Apress, 2004

It also seems like you might be wanting some direction on things like
ORM and database abstraction. Have you looked into what some of the
PHP-based frameworks are doing in this regard? I know they're PHP5-only
but studying projects like Symfony and the new Zend Framework have
really helped my understanding quite a bit.

Of course, the usual disclaimers apply.

HTH,

GM


-- 

Greg Maruszeczka
Websage Solutions
http://websage.ca
skype: websage.ca

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



[PHP] Beginner Tutorials for using CLASSES in PHP4

2007-09-29 Thread Jeff Cohan
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



Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Nathan Nobbe
Merlin,

if you are using php5 the var keyword is no longer valid; that was used in
classes in php4.
if you want to structure your classes properly you need to study PPP
(public, private, protected) access modifiers.
typically member variables are declared to be private or protected, if there
will be child
objects that will access them directly.  to provide access to said member
variables
creates public method.  public methods are visible to external code and have
access to the
private members, be they variables or methods.

-nathan

On 9/29/07, Merlin <[EMAIL PROTECTED]> wrote:
>
> Hi there,
>
> I am new to PHP classes and I do want to access a variable outside the
> class, but somehow that does not work. global also does not have any
> effect.
>
> In the following example I would like to be able to access $dbh from
> inside the class like I did in that example. This does not work. Can
> somebody please give me a hint on the right syntax?
>
> $dbh = 'test';
>
> class search_helper extends AjaxACApplication
>  {
>  /**
>   * Database connection details
>   */
>
>  var $db_hostname = $dbh;
>
> Thank you for any help,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


Re: [PHP] Re: languages and PHP

2007-09-29 Thread tedd

At 12:36 PM -0500 9/28/07, Edward Vermillion wrote:
My question was more mental prodding than anything else. The OP had 
a function to convert incoming text into UTF-8 before they did 
anything with it. A couple of folks said that was unnecessary, if 
you set your form to UTF-8 your incoming data will be in UTF-8 
already.


I was just trying to make the point that if you expect your incoming 
data to be in a certain state in your code you should make sure that 
it is in that state before you act on it, since you can't guarantee 
it's source. Checking to make sure the incoming data is in it's 
expected state is not a waste of time (or unnecessary, or whatever 
term of derision they picked) but is actually good coding practice.


I pretty much gave up on the thread when I got the reply along the 
lines of "if it breaks something it's their problem, not mine".


Ed


I still don't see the problem: If you are receiving in UTF-8 and 
someone sends you something UTF-8 or less, than you can catch it. If, 
on the other hand you are set up for a lessor charset, then there's 
no way you can be assured that what they send, you can catch.


If given the choice, use the super-group.

This is too obvious, I must be missing something.

Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

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



Re: [PHP] Classes and access to outside variables

2007-09-29 Thread Martin Alterisio
Refer to the global on the constructor.

Anyway, using a global like that is not a good practice. Just pass the
variable to the constructor.

2007/9/29, Merlin <[EMAIL PROTECTED]>:
>
> Hi there,
>
> I am new to PHP classes and I do want to access a variable outside the
> class, but somehow that does not work. global also does not have any
> effect.
>
> In the following example I would like to be able to access $dbh from
> inside the class like I did in that example. This does not work. Can
> somebody please give me a hint on the right syntax?
>
> $dbh = 'test';
>
> class search_helper extends AjaxACApplication
>  {
>  /**
>   * Database connection details
>   */
>
>  var $db_hostname = $dbh;
>
> Thank you for any help,
>
> Merlin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


[PHP] Classes and access to outside variables

2007-09-29 Thread Merlin

Hi there,

I am new to PHP classes and I do want to access a variable outside the 
class, but somehow that does not work. global also does not have any effect.


In the following example I would like to be able to access $dbh from 
inside the class like I did in that example. This does not work. Can 
somebody please give me a hint on the right syntax?


$dbh = 'test';

class search_helper extends AjaxACApplication
{
/**
 * Database connection details
 */

var $db_hostname = $dbh;

Thank you for any help,

Merlin

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