Re: [PHP] documentation on pg_escape_string()

2003-03-17 Thread Joe Conway
Dennis Gearon wrote:
Anyone know where to find documentation on this? Who knows what it escapes?

From PostgreSQL source (~/pgsql/src/interfaces/libpq/fe-exec.c):

8
/* ---
 * Escaping arbitrary strings to get valid SQL strings/identifiers.
 *
 * Replaces \\ with  and ' with ''.
 * length is the length of the buffer pointed to by
 * from.  The buffer at to must be at least 2*length + 1 characters
 * long.  A terminating NUL character is written.
 * ---
 */
size_t
PQescapeString(char *to, const char *from, size_t length)
8
I presume the PHP function is just a wrapper around this one (but did 
not actually check).

HTH,

Joe



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


Re: [PHP] defining vars within functions as global

2002-09-05 Thread Joe Conway

Justin French wrote:
 ?
 function foo()
 {
 $foo = aaa;
 $bar = bbb;
 }
 
 foo();
 
 echo $foo;
 echo $bar;
 
 ?
 
 How to I specify that $foo and $bar (defined in the func) are to be set
 globally (ie, outside the function)?

Why not use an include instead of a function?

Joe


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




Re: [PHP] Re: pgSQL Functions with results set to php?

2002-07-14 Thread Joe Conway

Richard Lynch wrote:
List,
I'm creating a PHP/pgSQL web site...I need to execute queries with a 
cursor and get their result set into my PHP script.  How can I make a 
pgSQL procedure with logic that also returns a result set?  I've 
searched and searched but cannot find the answer.  Does anyone got it?
 
 
 Any old select will return a result set that works with a query...
 
 But if you need your PostgreSQL FUNCTION to return a result set, I *think*
 you need to use:
 
 'set of XXX'
 
 for the 'rettype' (return type)
 
 and I *THINK* you can figure out what to use for XXX if you start digging to
 find the name/oid of the complex type that represents a row in your table
 here:
 
 http://www.postgresql.org/idocs/index.php?catalog-pg-type.html
 
 I've never done this, I just did a little digging right now, and this is
 where I would keep digging if I was working on this...
 
 But it sounds to me like PostgreSQL already *has* a complex type to
 represent the tuples in your table, and you just need to find out what the
 name of that complex type might be.  It may even turn out to be just the
 table name or something...
 

A complex, or aka composite, type in PostgreSQL is represented by 
the name of a table or view. The capability to return setof 
a-composite-type exists in a limited way in PostgreSQL 7.2.x. See the 
thread at:

   http://archives.postgresql.org/pgsql-interfaces/2002-06/msg00042.php

for a recent discussion about this with some examples.

PostgreSQL 7.3, when it is released, will have much better capability. 
You will be able to do:

test=# select * from getfoo(1);
   fooid | f2
---+-
   1 |  11
   1 | 111
(2 rows)

In cvs HEAD you can do this already with SQL language functions and C 
language functions.

HTH,

Joe


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




Re: [PHP] two way encryption

2002-07-14 Thread Joe Conway

Justin French wrote:
 I'm getting the following error using 4.1.1:
 Fatal error: Call to undefined function: mcrypt_create_iv() in
 /usr/local/apache/htdocs/tests/enc.php on line 3
 
 Which is confusing, given that the manual says mcrypt_create_iv() is
 available in PHP 4.

Looks like your ISP doesn't have mcrypt support. What does phpinfo() show?

General encryption advice -- generate your key using urandom and save it 
to your key file. It will be much more secure than anything you can 
think up for a good key.

HTH,

Joe



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




Re: [PHP] two way encryption

2002-07-14 Thread Joe Conway

Justin French wrote:
 Well, that was on my local test server, which I didn't compile with
 mcrypt... so that solves that, but it appears my ISP didn't compile with it
 either... so there's very little point in getting my local server working
 with it.
 
 What alternatives do I have?

I don't *think* PHP includes any builtin-by-default, non-one-way 
encryption functions, but I haven't looked in a long time so I could be 
wrong. You might be able to get your ISP to install mcrypt itself which 
has a command line utility. Then you could use passthru() I suppose.

Joe


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




Re: [PHP] Padding with mcrypt_generic

2002-01-15 Thread Joe Conway (wwc)

Ben Sinclair wrote:

 That would work for me, but I have to deal with many files that I have already
 encrypted and no longer know the correct sizes of. My search and replace for
 the padding characters doesn't work because the files sometimes contain those
 padding characters.
 
 --
 Ben Sinclair
 [EMAIL PROTECTED]

Well, if your original files ended in NUL bytes you are out of luck, but 
I don't think that is likely. You should be able to simply decrypt and 
strip trailing NUL bytes to get the original files back. See example below.

-- Joe
=

?PHP
print (HTMLBODY\n);

$plaintext = 123456789;
echo Plaintext =  . $plaintext . BR;
echo Plaintext length =  . strlen($plaintext) . BR;

/*
  * open the desired module
  */
$td = mcrypt_module_open (MCRYPT_TRIPLEDES, , MCRYPT_MODE_CBC, );

/*
  * Just for illustration, a real iv should be random of course
  */
$iv = ;

/*
  * and I hope a better password is actually used
  */
$key = mysecret;

/*
  * initialize the module structures
  */
$ret = mcrypt_generic_init($td, $key, $iv);

/*
  * finally encrypt it
  */
$ciphertext = mcrypt_generic($td, $plaintext);

echo Ciphertext length =  . strlen($ciphertext) . BR;

/*
  * get ready for decryption
  */
$ret = mcrypt_generic_init($td, $key, $iv);

/*
  * now decrypt
  */
$newplaintext = mdecrypt_generic($td, $ciphertext);

$ptr = strlen($newplaintext);
echo New plaintext length =  . $ptr . BR;

while (substr($newplaintext, $ptr - 1, 1) == chr(0))
{
$ptr--;
}

$origplaintext = substr($newplaintext, 0, $ptr);
echo Origplaintext =  . $origplaintext . BR;
echo Origplaintext length =  . strlen($origplaintext) . BR;

print (/BODY/HTML\n);
?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Padding with mcrypt_generic

2002-01-14 Thread Joe Conway (wwc)

Ben Sinclair wrote:

 I'm trying to use mcrypt_generic and it works fine except it pads the data
 with ^@'s when, according to the manual page, the length of the data is not
 n * blocksize.
 
 I've been trying to remove the padding from my decrypted data using
 something like $string = str_replace(^@,,$string);, but it doesn't
 seem to work right (^@ is a single character, not just ^ . @).
 
 Has anyone had to do this before and found a solution?
 
 --
 Ben Sinclair
 [EMAIL PROTECTED]

I worked around this by padding the plaintext myself. Basically, add NUL 
(character 0) bytes so that your plaintext becomes an exact multiple of 
blocksize. Then change the very last byte to the number of padding bytes 
used. If the plaintext is already an exact multiple of blocksize, then 
pad with an entire block.

On decryption, reverse the process, and you'll have your original string 
back exactly the way you started.

Here are two functions that I use for this:
(note: I modified these slightly from the originals without testing)

function pad_plaintext($data, $blocksize)
{
 $buffer = ;
 $numpad = $blocksize - (strlen($data) % $blocksize);

 $nul_str = chr(0);
 $buffer = $data . str_repeat($nul_str, $numpad);
 $buffer[strlen($buffer) - 1] = chr($numpad);

 return($buffer);
}

function depad_plaintext($data)
{
 $buffer = ;
 $numpad = ord($data[strlen($data) - 1]);

 $buffer = substr($data, 0, -1 * $numpad);

 return($buffer);
}

HTH,

--Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Decryption

2002-01-13 Thread Joe Conway

John Cuthbert wrote:

 
 Is there a method for decrypting encrypted things by md5?

No. MD5 is a one-way hash, *not* a form of encryption. A hash is 
specifically designed so that it is impractical to find the input 
string, given the output string.

If you need to encrypt/decrypt, look at the mcrypt extension and use 
3DES or one of the other symmetrical encryption algorithms.

HTH,

--Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Use PHP to connect to Oracle 8i database

2001-08-27 Thread Joe Conway

 I want to use php to connect to an Oracle 8i database.

 I have 2 questions:
 1) does the webserver have to be installed on the
 database server?

No -- you just have to configure your tnsnames.ora so that the web server
can connect. Try sqlplus first. If you can connect with sqlplus, you should
be able to connect from PHP.

 2) do you have to use the OCI libraries?


Yes, you do need the oracle client.

See http://www.php.net/manual/en/ref.oci8.php for more info. Particularly
see the note on pthread.

HTH,

-- Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP based statistics/Graphs

2001-07-21 Thread Joe Conway

 On Tue, Jul 17, 2001 at 10:48:24PM -0700, Rasmus Lerdorf wrote:
  I like Vagrant.  See http://vagrant.sourceforge.net
 
 I prefer R :) http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
 
 It is IMHO the best language for statistic.
 
 -Egon

Do you know if anyone is working on a PHP extension for R?

-- Joe



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] need some ideas here...

2001-05-14 Thread Joe Conway

 My free-web-hosting (www.f2s.com) does not allow PHP to send emails...
I've
 tried everything... the mail() function, my alternate function which calls
 popen(/usr/lib/sendmail -t) and even a script.cgi with '#!/usr/bin/php'
 and all that stuff...

 the mail simply won't go an mail() always returns false...
 I'm guessing there's no mail sending in this server...

 so what do I do?

If you know an SMTP server that will allow you to relay mail, you can use
fsockopen and write the mail directly to the port 25 on the relay server. I
haven't tried it with PHP, but I've done something similar with tcl before.
You might try finding something like this already written.

-- Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] php/postgres display information...

2001-05-08 Thread Joe Conway

 hey guys,
 alright, I am new to using php to interface with a database, right now I
 am trying to display just the primary keys for a table in my database, can
 someone point me in the right direction on how to use php to display this
 information?

Create a function to supply the info -- see:
http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=36

Then call the function:

?PHP
$conn = pg_connect(dbname=your_db_name user=your_user_name
password=your_password);
$sql = select get_pk('your_table_name');
$rs = pg_exec($conn,$sql);

 . . .etc

Hope this helps,

Joe




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Recursive Childs

2001-04-22 Thread Joe Conway

Subject: [PHP] Recursive Childs

snip

 like hotscripts.com too, so i thought if someone could tell me how to use
get all the children :

 ID | NAME | PARENT
 1X  0
 2Y  1
 3Z  2
 4A  2
 5F  1
 6G  5
 if i want to get all children of 1, i want to get 2, 3, 4, 5, 6!

 how do i get this, thanks!


Hi Natasha,

As your subject implies, the way to do this is with a recursive function
call. Assuming your data is in a PostgreSQL database table, you could use
something like the following (*untested* -- modify as required if you are
using MySQL or something else)

Hope this helps!

Joe

*

?PHP
function getChildren($conn,$parent,$level,$currentrecord,$rowclr)
{ 
 $level += 1;
 $levelpad = "";
 for($counter = 0; $counter  $level - 1; $counter++)
 {
  $levelpad = $levelpad . "-";
 }

 $levelpad = $levelpad . "";
 If (! empty($parent))
 { 
  $sql = "select id, name, parent from mytable where parent =$parent order by id";
  $rs = pg_exec($conn,$sql);
  
  for ($row = 0; $row = pg_numrows($rs) - 1; $row++)
  {
   $currentrecord += 1;
   if ($rowclr == "#d7d7d7")
   {
$rowclr = "#ff";
   }
   else
   {
$rowclr = "#d7d7d7";
   }
   for ($field = 0; $field = pg_numfields($rs) - 1; $field++)
   {
$rsf[pg_fieldname($rs,$field)] = pg_result($rs,$row,$field);
   }
   print("tr bgcolor=\"" . $rowclr . "\"\n");
   print("td align=\"left\"" . $levelpad . $rsf["id"] . "nbsp;/td\n");
   print("td align=\"left\"" . $rsf["name"] . "nbsp;/td\n");
   print("td align=\"center\"" . $level . "nbsp;/td\n");
   print("/tr\n");
   
   $newparent = $rsf["parent"];
   getChildren($conn,$newparent,$level,$currentrecord,$rowclr);
  };
  pg_freeresult($rs);
 }
 else
 {
  print("h3No information found./h3\n");
 }
}

  $conn = pg_connect("dbname=mydb user=postgres");
  $parent = 0;
  $level = 0;
  $currentrecord = 0;

  $rowclr = "#e7e7e7";

  print("HTMLBODY\n");

  print("table cellspacing=\"1\" cellpadding=\"1\" width=\"100%\"\n");
  print("tr bgcolor=\"#BB\"\n");
  print("th align=\"left\"ID/th\n");
  print("th align=\"left\"Name/th\n");
  print("th align=\"center\"Level/th\n");
  print("/tr\n");

  getChildren($conn,$parent,$level,$currentrecord,$rowclr);

  print("/TABLE\n");
  if ($currentrecord == 0)
  {
   print("H3No matches found./H3\n");
  }
  print("/BODY/HTML\n");

?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Recursive Childs

2001-04-22 Thread Joe Conway

Subject: Re: [PHP] Recursive Childs
 thanks for that, could you just explain how it should start, should i just
call the function, how does the level get determined ???

After the function ends, starting at
*
  $conn = pg_connect("dbname=mydb user=postgres");

*
is an example of how to call the function. Level starts out as level 0. Each
time the function is called, it increments the value of level that was
passed to it -- therefore a child of parent = 0 is at level 1, and a child
of parent 1 is at level 2, etc. The part that initializes everything is:

*
  $conn = pg_connect("dbname=mydb user=postgres");
  $parent = 0;
  $level = 0;
  $currentrecord = 0;
  $rowclr = "#e7e7e7";
*

Change $parent to something else to start at a different point in your tree.
$level can start with whatever value you want. The next part starts an HTML
document and the table, then calls the recursive function, getChildren.
getChildren calls itself recursively to build the table. When the function
emerges again at the top level, the table and html document are ended.
*
  print("HTMLBODY\n");

  print("table cellspacing=\"1\" cellpadding=\"1\" width=\"100%\"\n");
  print("tr bgcolor=\"#BB\"\n");
  print("th align=\"left\"ID/th\n");
  print("th align=\"left\"Name/th\n");
  print("th align=\"center\"Level/th\n");
  print("/tr\n");

  getChildren($conn,$parent,$level,$currentrecord,$rowclr);

  print("/TABLE\n");
  if ($currentrecord == 0)
  {
   print("H3No matches found./H3\n");
  }
  print("/BODY/HTML\n");
 *

That's it -- it's actually pretty simple.

- Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Apache user

2001-04-05 Thread Joe Conway

 Can anyone tell me how to get the user apache is running as from php?
 
If you're on Linux/Unix, try:

echo `whoami`;

Hope this helps,

Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Apache user

2001-04-05 Thread Joe Conway

Actually no need for that if you use backticks. See
http://www.php.net/manual/en/html/language.operators.execution.html#language
.operators.execution

Joe

- Original Message -
From: "Johnson, Kirk" [EMAIL PROTECTED]
To: "PHP User Group" [EMAIL PROTECTED]
Sent: Thursday, April 05, 2001 11:32 AM
Subject: RE: [PHP] Apache user


 Put the call to "whoami" in a call to exec() from inside a PHP script.

 ?
 echo exec("whoami");
 ?

 Kirk

  -Original Message-
  From: Joe Conway [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, April 05, 2001 12:26 PM
  To: Chris Mason; PHP User Group
  Subject: Re: [PHP] Apache user
 
 
   Can anyone tell me how to get the user apache is running as
  from php?
  
  If you're on Linux/Unix, try:
 
  echo `whoami`;
 
  Hope this helps,
 
  Joe


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] key generation with mcrypt

2001-03-23 Thread Joe Conway

 Does anyone know a good way to generate /good/ keys for algorithms used
with
 mcrypt? I know openssl has key generation scripts, and it seems a little
 inane that mcrypt doesn't provide key generation functions. After all,
 encryption algorithms are not secure without sufficiently random and
 well-chosen keys.

 I surely /must/ be missing something! Please let me know.

 Dean Hall.

I'm sure there are "better" ways, but for what it's worth, here is what I
use to generate a good random key:

mt_srand((double)microtime()*100);
$rsess = uniqid(mt_rand());
$ksess = mhash(MHASH_SHA1, $rsess);

I think the basic code here originated somewhere in the annotated PHP
manual. Depending on the algorithm you use, different key lengths will be
appropriate, so just trim this to the required length. Note that this
requires MHash as well as MCrypt, but you could substitute the built in MD5
function for SHA1.

Hope this helps,

Joe



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] How to get oid after table insert? [postgresql]

2001-03-07 Thread Joe Conway

 I am working on a site using PHP (obviously) and PostgreSQL. I am 
 currently using the oid as a key on a table. I would like to return the 
 user to the same record after INSERTing it, but I cannot figure out how 
 to get the oid of the record after doing an INSERT. Ideally, I would 
 like something like:
 
 So, how do I insert a new record into the database, and get the oid of 
 the record I just inserted?
 

See http://www.php.net/manual/en/function.pg-getlastoid.php

Hope this helps,

Joe



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] generate e.g. circles on the fly with coordinates for postioning

2001-02-24 Thread Joe Conway

Subject: [PHP] generate e.g. circles on the fly with coordinates for
postioning


Can php + what modules do this and
has anybody succeeded to do something like the followingbefore?

I want to generate simple images on the fly, e.g. a 50px circle on a
transparent background of 200x200 px using php.

I want to position the circle on the background using  x and y coodinates.
Is this possible with what php and additional tools?

Sure can. Take a look at: http://www.php.net/manual/en/ref.image.php

Hope this helps,

Joe


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] PHP/Oracle mod

2001-02-12 Thread Joe Conway

 I'm really struggling configuring the php mod with oracle 8i support on
 Solaris 8.

 ./configure --enable-track-vars --with-o8ci=/export/home/oracle
 --with-oracle --enable-sigchild --with-apxs

 The ORACLE_HOME is set to /export/home/oracle.

 I am getting an error:

 checking Oracle Install-Dir...
 ++
 | Notice:|
 | If you encounter defunc processes when using a local Oracle-DB   |
 | please recompile PHP and specify --enable-sigchild when configuring|
 | (This problem has been reported un Linux using Oracle = 8.1.5)|
 ++
 checking Oracle version... configure: error: Oracle needed libraries not
found

 I installed the oracle 8i client prior to compiling. I've installed all
 the compilers, Please God, WHAT HAVE I DONE WRONG.  If anyone out
 there can help this poor wrech of a man. Please help me..

Richard,

Below is a copy of my reply to someone else on this topic from last June (so
I'm not entirely sure the -lpthread part still applies). It sounds like the
error message might be related to the LD_LIBRARY_PATH envoronment setting.
Alternatively, I think you can edit /etc/ld.so.conf to add a line pointing
to your $ORACLE_HOME/lib, and then run ldconfig.

Hope this helps,

Joe

old email
I had a similar problem which took two actions to solve it. First, recompile
apache after adding
"-lpthread" (without the quotes)
to the LIBS1 line in the makefile. Apparently this is related to a known
glibc bug and the fact that the oracle client library is threaded.
Alternatively you can add
"LIBS=-lpthread \" (no quotes)
just before OPTIM="$RPM_OPT_FLAGS" \ in the apache.spec file if you want to
work from an RPM source file (this is what I did).

The second thing to check is that you have LD_LIBRARY_PATH=$ORACLE_HOME/lib
defined in your environment.

Hope this helps.

Joe
/old email




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] help with classes

2001-02-12 Thread Joe Conway

 Was just wondering how to do the following:

 ?php
 class Foo {

 var $bar = $foo; // causes parse error
 var $bar = "$foo"; // causes parse error
 var $bar = '$foo'; // works but $foo is not evaluated

 }
 ?

 So how does one correctly assign a variable to a variable inside a class
withot doing something like:

 var $bar = '';
 $this-bar = $foo;

 Any insight would be much appreciated.

I was curious too, so I looked it up. Seems you can't. From
http://www.php.net/manual/en/language.oop.php

"Note: In PHP 4, only constant initializers for var variables are
allowed. Use constructors for non-constant initializers."

Hope this helps,

Joe




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] help with classes

2001-02-12 Thread Joe Conway

 SC
 SC That's how you have to do it.
 SC
 SC
 SC class MyClass {
 SC var $bar;
 SC
 SC // This is the class's constructor
 SC sub MyClass () {
 SC $this-bar = $foo;
 SC }
 SC }

 I didn't think php had sub routines like perl? shouldn't that be:

 function MyClass(){
   $this-bar = $foo;
 }

 I tried this and it does not evaluate the variable. The only way I could
get this to work was to create a function that I can pass the variable to as
one of it paramaters (see previous post)

 I could be wrong?



Is this closer to what you were looking for?
- Joe

?PHP

 class Foo {

 var $bar;

 function mymethod(){

  global $foo;
  $this-bar = $foo;

 }

}

$foo = "hello world";

echo "htmlbody";

$cls = new foo();
$cls-mymethod();
echo $cls-bar;

echo "/body/html";
?


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Mathematical prob

2001-02-12 Thread Joe Conway

 Okay, im a little stumped. I have been asked to use a formula which
 calculates Monthly Repayments on a mortgage loan. The formula I have been
 given is

 M = P * ( J / (1 - (1 + J) ** -N))

 My problem is, the last part. It explains it in english as "then take that
 to the -N (minus N) power"

 My problem is, I have no idea how to put this into a PHP script so that it
 can calculate it out. I have a feeling im falling short at the "to the
 power of" part. I tried to do a 3 to the power of 3 calculation and I cant
 get it to spit out 27 like I know it should.


Chris,

I think this is what you're looking for:

?PHP
echo "htmlbody";

// principle
$P = 18;

// annual rate divided by 12 months
$J = 0.0775/12;

// 30 years times 12 months
$N = 360;

// monthly payment
$M = $P*($J/(1-pow((1+$J),-$N)));

echo $M;

echo "/body/html";
?

Hope this helps,

Joe



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]