Member Avatar for diafol

Having just found 'traits' - see http://www.daniweb.com/web-development/php/threads/468928/php-trait-method-conflicts-trait-inheritance#post2043565

I was wondering whether they could be used to share a DB connection object across disparate classes, or would the old singleton or dependency injection methods still be the way to go? I'd value any views on this.

Recommended Answers

All 2 Replies

I like the introduction here but I'm afraid traits will most likely be used like global functions. Most applications I've seen so far are dubious, more play than proper design. Traits come near multiple inheritance, and there's good reason most languages do not support it. It gets messy quickly. Personally I'd have much rather had them implementing proper interfaces.

Member Avatar for diafol

Fair points. I was just looking at whether I'd be able to give classes DB methods without having to pass the object (DI) or creating a singleton/static. I didn't really think it through that well I suppose. Ah well, at least my string-manipulation functions don't need to be base-classed or DI'd any more :)
Thanks for the link and your views.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.