php-general Digest 29 Sep 2007 23:29:51 -0000 Issue 5045
Topics (messages 262576 through 262582):
Re: Classes and access to outside variables
262576 by: Martin Alterisio
262578 by: Nathan Nobbe
Re: languages and PHP
262577 by: tedd
Beginner Tutorials for using CLASSES in PHP4
262579 by: Jeff Cohan
262580 by: Greg Maruszeczka
262581 by: Jeff Cohan
262582 by: Instruct ICC
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 ---
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
>
>
--- End Message ---
--- Begin Message ---
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
>
>
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
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
--- End Message ---
--- Begin Message ---
> 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
--- End Message ---