You are here: Re: Using a Resource as a Class Property « PHP Programming Language « IT news, forums, messages
Re: Using a Resource as a Class Property

Posted by Sanders Kaufman on 07/24/07 00:57

Jerry Stuckle wrote:
> Sanders Kaufman wrote:

>> Also, the idea of doing this:
>> "$x = new MyObject($y, $z)"
>> instead of this:
>> "$x = new MyObject()"
>> just *feels* wrong to me.
>>
>> I'm not sure why - but it's probably legacy cringing from some other
>> platform and package in my past.
>>
>
> Not at all. The whole purpose of the constructor is to initialize the
> object. It is probably more common to pass parameters to the object's
> constructor than not.
>
> For instance, the constructor for the mysqli class:
>
> mysqli mysqli_connect ( [string host [, string username [, string passwd
> [, string dbname [, int port [, string socket]]]]]] )
>
> If you pass a host, it will try to connect to the host. If you pass a
> username, it will connect using that username. If password is
> specified, it will also use that password, etc.
>
> If no parameters are specified, then no connection is attempted.

Yeah - I'm totally cool with the fact that some folks use parms in the
construction, and on a thinky level, I can certainly see where it would
be handy. But it really feels wrong.

I have the same issue with using voids... although I use 'em, it just
feels like the same kind of wrong.


>> This looks like something I'm going to have to HEAVILY consider in the
>> next iteration of the code - abstract classes, interfaces and function
>> overrides.
>
> Yep.
>
> I'd also recommend you pick up a decent book on OO in general. It will
> explain things a lot better than we can here in the newsgroup.

I'm not very good about learning from tutorial books. I get all the way
through, don't miss a thing, do all of the exercises... and then have no
idea what I learned.

If I'm gonna learn this stuff, it's gonna be because someone taught it
to me here and in the OOP groups. I'll probably also draw up a nice
poster to remind me about Inheritance, Polymorphism, Abstraction and
Encapsulation.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация