[PHP] PHP5 objects access/instantiation model

2007-07-11 Thread Steve Perkins

Hi, new to PHP5 and I have a question about the object model. 

I want to be able to create a class which is allows abstraction from
specifics. So for one example, imagine a generic database connection wrapper
which can have multiple drivers depending on the database used. Some of the
functionality is generic, some is database specific (mysql_ , odbc_). So:

Class MySQL_driver {
public prop1 ;
public connect() {
echo "Foo";
}
public runquery() {
echo "Foo";
}
...
}

Class ODBC_driver {
public prop1 ;
public connect() {
echo "Foo";
}
public runquery() {
echo "Foo";
}
...
}

Class generic {
public $driver = null ;
function __construct($connection_type) {
if $this->connection_type = "MySQL" {
$this->driver = new MySQL_Driver ;
} else {
$this->driver = new ODBC_Driver ;
}
}
function authenticate { // Using the
non-generic connect() from the selected driver
$this->driver->prop1 = "fooey"  // These references
work fine from within the generic class
echo $this->driver->prop1 ; 
echo $this->driver->function1 ;
}
function errors {   //
Reporting non-generic errors from the selected driver
}
function debug {
}

...

}

$gen = new generic("MySQL") ;   //
Instantiate the generic database object, which determines its own driver

$gen->driver->prop1 = "fooey"   // but they
fail from here
echo $gen->driver->prop1 ;  
echo $gen->driver->function1 ;

$gen->authenticate() ;  // this
works ok though, so everything is created correctly


So I want to access generic functions as $generic->authenticate(), and
database specific functions $generic->driver->runquery. This allows the top
level code to be able to be completely generic and not know anything about
the underlying database.

But I can't ! I can't find a way of accessing the encapsulated object
(driver) from the instantiator of generic. Is it possible ?

I guess there are lots of "workaround" ways. I could write lots of
"middleman" code in generic and use things like __set and __get etc but its
lots of extra overhead. I also know I could use extends but that makes the
code the wrong way around (MySQL_Driver would have to extend generic), hence
the top-level application would have to include code to determine which
driver to create rather than the db object determining its own connection
driver to use. This is true also for just lumping everything in a single
class per db type.

Surely it must be possible ? Or am I missing something ? 

I also don't really get the idea of interface and abstract classes ? They
don't seem to be any practical use ? Maybe that's me ? Anyway, not really
relevant to this post ...

Please, please can someone help !!

Thanks

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



[PHP] PHP5 objects access/instantiation model (correction)

2007-07-11 Thread Steve Perkins
OK, so that came out fairly illegible. Try again:

Hi, new to PHP5 (and the forums evidently !) and I have a question about the
object model.

I want to be able to create a class which is allows abstraction from
specifics. So for one example, imagine a generic database connection wrapper
which can have multiple drivers depending on the database used. Some of the
functionality is generic, some is database specific (mysql_ , odbc_). So:

Class MySQL_driver {
public prop1 ;
public connect() {
echo "Foo";
}
public runquery() {
echo "Foo";
}
...
}

Class ODBC_driver {
public prop1 ;
public connect() {
echo "Foo";
}
public runquery() {
echo "Foo";
}
...
}

Class generic {
public $driver = null ;
function __construct($connection_type) {
if $this->connection_type = "MySQL" {
$this->driver = new MySQL_Driver ;
} else {
$this->driver = new ODBC_Driver ;
}
}

// Using the non-generic connect() from the selected driver

function authenticate {
$this->driver->prop1 = "fooey" 

// These references work fine from within
// the generic class

echo $this->driver->prop1 ;
echo $this->driver->function1 ;
}

// Report non-generic errors from the selected driver

function errors {  
}
function debug {
}

...
   
}
   
$gen = new generic("MySQL") ;  

// Instantiate the generic database object, which
// determines its own driver

$gen->driver->prop1 = "fooey"  

// but they fail from here

echo $gen->driver->prop1 ; 
echo $gen->driver->function1 ;

// this works ok though, so everything is created
// correctly

$gen->authenticate() ; 


So I want to access generic functions as $generic->authenticate(), and
database specific functions $generic->driver->runquery. This allows the top
level code to be able to be completely generic and not know anything about
the underlying database.

But I can't ! I can't find a way of accessing the encapsulated object
(driver) from the instantiator of generic. Is it possible ?

I guess there are lots of "workaround" ways. I could write lots of
"middleman" code in generic and use things like __set and __get etc but its
lots of extra overhead. I also know I could use extends but that makes the
code the wrong way around (MySQL_Driver would have to extend generic), hence
the top-level application would have to include code to determine which
driver to create rather than the db object determining its own connection
driver to use. This is true also for just lumping everything in a single
class per db type.

Surely it must be possible ? Or am I missing something ?

I also don't really get the idea of interface and abstract classes ? They
don't seem to be any practical use ? Maybe that's me ? Anyway, not really
relevant to this post ...

Please, please can someone help !!

Thanks

--
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



RE: [PHP] PHP5 objects access/instantiation model (correction)

2007-07-11 Thread Steve Perkins
Yeah. I've been working on re-writing it using bits from everyone !! It's a
good learning process to find out how PHP handles OOP. I thoroughly
recommend it, it's the only way to learn. Some things just can't be learnt
from the manual!

Cheers All.

-Original Message-
From: Richard Lynch [mailto:[EMAIL PROTECTED] 
Sent: 11 July 2007 21:29
To: Steve Perkins
Cc: php-general@lists.php.net
Subject: Re: [PHP] PHP5 objects access/instantiation model (correction)

You probably ought to have:

class mysql_driver extends generic_driver { }

Seems like that would be the most reasonable OOP model, imho.



That said, I suspect that if you do something like:

$driver = $this->driver;

You then may be able to access the driver-specific data using
$driver->propl; etc.

On Wed, July 11, 2007 10:46 am, Steve Perkins wrote:
> OK, so that came out fairly illegible. Try again:
>
> Hi, new to PHP5 (and the forums evidently !) and I have a question 
> about the object model.
>
> I want to be able to create a class which is allows abstraction from 
> specifics. So for one example, imagine a generic database connection 
> wrapper which can have multiple drivers depending on the database 
> used. Some of the functionality is generic, some is database specific 
> (mysql_ , odbc_).
> So:
>
> Class MySQL_driver {
> public prop1 ;
> public connect() {
> echo "Foo";
> }
> public runquery() {
> echo "Foo";
> }
> ...
> }
>
> Class ODBC_driver {
> public prop1 ;
> public connect() {
> echo "Foo";
> }
> public runquery() {
> echo "Foo";
> }
> ...
> }
>
> Class generic {
> public $driver = null ;
> function __construct($connection_type) {
> if $this->connection_type = "MySQL" {
> $this->driver = new MySQL_Driver ;
> } else {
> $this->driver = new ODBC_Driver ;
> }
> }
>
>   // Using the non-generic connect() from the selected driver
>
> function authenticate {
> $this->driver->prop1 = "fooey"
>
> // These references work fine from within
> // the generic class
>
> echo $this->driver->prop1 ;
> echo $this->driver->function1 ;
> }
>
>   // Report non-generic errors from the selected driver
>
> function errors {
> }
> function debug {
> }
>
> ...
>
> }
>
> $gen = new generic("MySQL") ;
>
> // Instantiate the generic database object, which // determines its 
> own driver
>
> $gen->driver->prop1 = "fooey"
>
> // but they fail from here
>
> echo $gen->driver->prop1 ;
> echo $gen->driver->function1 ;
>
> // this works ok though, so everything is created // correctly
>
> $gen->authenticate() ;
>
>
> So I want to access generic functions as $generic->authenticate(), and 
> database specific functions $generic->driver->runquery. This allows 
> the top level code to be able to be completely generic and not know 
> anything about the underlying database.
>
> But I can't ! I can't find a way of accessing the encapsulated object
> (driver) from the instantiator of generic. Is it possible ?
>
> I guess there are lots of "workaround" ways. I could write lots of 
> "middleman" code in generic and use things like __set and __get etc 
> but its lots of extra overhead. I also know I could use extends but 
> that makes the code the wrong way around (MySQL_Driver would have to 
> extend generic), hence the top-level application would have to include 
> code to determine which driver to create rather than the db object 
> determining its own connection driver to use. This is true also for 
> just lumping everything in a single class per db type.
>
> Surely it must be possible ? Or am I missing something ?
>
> I also don't really get the idea of interface and abstract classes ?
> They
> don't seem to be any practical use ? Maybe that's me ? Anyway, not 
> really relevant to this post ...
>
> Please, please can someone help !!
>
> Thanks
>
> --
> 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
>
>


--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
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



RE: [PHP] mail function from and reply to address problem

2007-07-12 Thread Steve Perkins
Sounds more like the mail server than PHP. Although weird anyway ! What mail
server are you using : local/remote, smtp/sendmail/qmail ? 

Try using whatever method and send a mail through this server from outside
of PHP with the same problem parameters ? Does that work ? It should either
eliminate PHP, or point the finger ! I suspect eliminate but you never
know..

That's where I think I'd start anyway. Send uz an update when you have some
answers.

Steve


-Original Message-
From: Tanner Postert [mailto:[EMAIL PROTECTED] 
Sent: 13 July 2007 00:33
To: php-general@lists.php.net
Subject: [PHP] mail function from and reply to address problem

I am currently running

PHP 5.1.4
Fedora Core 5

i'm trying to exectute the following test script.



i have about 10 or so different virtual hosts running on this machine, and
if i use any of them for the from & reply-to addresses, it works fine, or
even if i use domains I don't control like aol.com or example.com those work
too, but one particular new virtual host doesn't work, it re-writes the from
address to the default virtual host address. which is strange because that
isn't in the php.ini anywhere, but it could just be taking the hostname.

anyone have any ideas?

thanks in advance.

Tanner

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



FW: [PHP] SMS questions

2007-07-13 Thread Steve Perkins
Richard makes some good points.

Further to the original posting though, I have a friend who works with this
SMS stuff, and out of interest asked him about it. Here is his (slightly
scary) response, might be of some use ...

His website is www.textit,biz 



-Original Message-
From: Shaun M. Nixon
Sent: 13 July 2007 09:17
To: Steve Perkins [mailto:[EMAIL PROTECTED]
Subject: FW: [PHP] SMS questions

Hi Steve

Hope you're doing fine.

It is possible.  In short, you have seen how a SMS message is sent using a
operators Name label i.e. the Messages says who it's from e.g. TEXT IT, but
you are unable to reply because the Sender is 'Text it' and not a mobile
number. Well in the same mechanism, you can send a mobile phone number as
the Label.  Thus allowing you to send someone a message as if it came from
someone else.  I guess this is what is being asked / wanted - spoofing a
Mobile.  

It is illegal to do this without consent and you must audit / prove
ownership / identity of the phone regarding the use / service (highly
regulated) - it also carries great risk to the provider (e.g. 2 Million fine
from ICTICS), hence most companies reluctance etc.

I believe Skype have recently introduced this service (but it's expensive)
if Brian wants to try it out.  We can do the same if required, as too relay
all reply messages via email / texts if needed.

Kind Regards
Shaun Nixon
Principal Consultant

W: www.textit.biz



-Original Message-
From: Steve Perkins [mailto:[EMAIL PROTECTED]
Sent: 13 July 2007 01:05
To: Shaun M. Nixon
Subject: FW: [PHP] SMS questions

I saw this and I though of you Shaun. You have any answers ? 
Cheers 
 

-Original Message-
From: Brian Dunning [mailto:[EMAIL PROTECTED] 
Sent: 13 July 2007 00:40
To: php-general@lists.php.net
Subject: [PHP] SMS questions

Hi all - I've been looking at a number of the commercial service providers
for bulk SMS messaging, most of whom have PHP APIs. But since they are
selling something they don't answer my question

Is there any (legal, legitimate) way to send an SMS message that can be
replied to the desired SMS cell number? Like, if I use PHP to send an SMS to
Bob, can I make it appear to come from Jim's cell phone so that Bob can
reply directly to Jim normally? The services all require Jim to log into
their web site to read any replies.

--
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



RE: [PHP] SMS questions

2007-07-15 Thread Steve Perkins

Sorry, www.textit.biz

Cheers


-Original Message-
From: Dan [mailto:[EMAIL PROTECTED] 
Sent: 13 July 2007 17:52
To: php-general@lists.php.net
Subject: Re: [PHP] SMS questions

Might want to retry that link, it's broken.

- Dan

""Steve Perkins"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Richard makes some good points.
>
> Further to the original posting though, I have a friend who works with 
> this SMS stuff, and out of interest asked him about it. Here is his 
> (slightly
> scary) response, might be of some use ...
>
> His website is www.textit,biz
>
>
>
> -Original Message-
> From: Shaun M. Nixon
> Sent: 13 July 2007 09:17
> To: Steve Perkins [mailto:[EMAIL PROTECTED]
> Subject: FW: [PHP] SMS questions
>
> Hi Steve
>
> Hope you're doing fine.
>
> It is possible.  In short, you have seen how a SMS message is sent 
> using a operators Name label i.e. the Messages says who it's from e.g. 
> TEXT IT, but you are unable to reply because the Sender is 'Text it' 
> and not a mobile number. Well in the same mechanism, you can send a 
> mobile phone number as the Label.  Thus allowing you to send someone a 
> message as if it came from someone else.  I guess this is what is 
> being asked / wanted - spoofing a Mobile.
>
> It is illegal to do this without consent and you must audit / prove 
> ownership / identity of the phone regarding the use / service (highly
> regulated) - it also carries great risk to the provider (e.g. 2 
> Million fine from ICTICS), hence most companies reluctance etc.
>
> I believe Skype have recently introduced this service (but it's 
> expensive) if Brian wants to try it out.  We can do the same if 
> required, as too relay all reply messages via email / texts if needed.
>
> Kind Regards
> Shaun Nixon
> Principal Consultant
>
> W: www.textit.biz
>
>
>
> -Original Message-
> From: Steve Perkins [mailto:[EMAIL PROTECTED]
> Sent: 13 July 2007 01:05
> To: Shaun M. Nixon
> Subject: FW: [PHP] SMS questions
>
> I saw this and I though of you Shaun. You have any answers ?
> Cheers
>
>
> -Original Message-
> From: Brian Dunning [mailto:[EMAIL PROTECTED]
> Sent: 13 July 2007 00:40
> To: php-general@lists.php.net
> Subject: [PHP] SMS questions
>
> Hi all - I've been looking at a number of the commercial service 
> providers for bulk SMS messaging, most of whom have PHP APIs. But 
> since they are selling something they don't answer my question
>
> Is there any (legal, legitimate) way to send an SMS message that can 
> be replied to the desired SMS cell number? Like, if I use PHP to send 
> an SMS to Bob, can I make it appear to come from Jim's cell phone so 
> that Bob can reply directly to Jim normally? The services all require 
> Jim to log into their web site to read any replies.
>
> --
> 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

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



RE: [PHP] magic quotes

2007-07-17 Thread Steve Perkins
Talking about .htaccess, anyone know an easy way of configuring os
(generally linux/windows) alternative settings in the same .htaccess ?
Mainly for paths (eg: include_path), so I can just upload a whole directory
at a time from my (Windows) development machine to a (Linux) production
server without having to worry about different .htaccess files for each.

Ta
Steve

-Original Message-
From: Richard Heyes [mailto:[EMAIL PROTECTED] 
Sent: 17 July 2007 12:25
To: Phil Princely
Cc: php-general@lists.php.net
Subject: Re: [PHP] magic quotes

> What do people on this list usually do with this kind of problem. To 
> me, the .htaccess seems the easiest solution, since I don't have to 
> change any scripts.

Use a .htaccess file, or if performance is any sort of concern, put it in
the server configuration files and turn off .htaccess files.

Failing that you could do it in the script with your
stripslashes_array() function, but you should only do it when you need to.
eg. There's no point using it on $_COOKIE if you're not using $_COOKIE.

--
Richard Heyes
+44 (0)844 801 1072
http://www.websupportsolutions.co.uk

Knowledge Base and HelpDesk software
that can cut the cost of online support

--
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