php-general Digest 12 Jul 2003 13:57:23 -0000 Issue 2171

Topics (messages 154943 through 154955):

Re: Private and protected variables in PHP 5?
        154943 by: Greg Beaver

Couple of questions form a PHP newbie
        154944 by: Jason Giangrande
        154945 by: Jonathan Villa
        154948 by: Jason Giangrande
        154950 by: Simon Fredriksson

Re: Mailing list server with PHP frontend
        154946 by: Tom Rogers

Re: How to hide URL but it's not from a form just a link ?
        154947 by: Tom Rogers
        154949 by: Justin French
        154952 by: Tom Rogers

Re: fread() question
        154951 by: Simon Fredriksson

Re: Mind exploded on this one!
        154953 by: Paul Chvostek

imagecreate() error
        154954 by: Michelle Bernard

Configuration Problems
        154955 by: Arun

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:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message --- Hi to both of you,

What is happening here is that there is a separate namespace for private elements in PHP 5. You can have both a private $Name and a public $Name if it is defined at runtime. I don't know if this is a feature or a bug, I'd call it a bug since redeclaration of a variable is not allowed, perhaps we should include the developers in on this question?

Try this script to see the duplicate $Name variable:

<?php
  class dog {
    // declare two private variables
    private $Name;
    private $DogTag;

    public function bark() {
      print "Woof!\n";
    }

    public function printName() {
      print $this->Name; // prints nothing!
    }
  }

  // new class, for testing derived stuff
  class poodle extends dog {
    public function bark() {
      print "Yip!\n";
    }
  }

  // I now create an instance of the
  // derived class
  $poppy = new poodle;

  // and set its private property
  $poppy->Name = "Poppy";
  print $poppy->Name. "\n";
  $poppy->printName();
  print_r($poppy);
?>

outputs:

Poppy
poodle Object
(
    [Name:private] =>
    [DogTag:private] =>
    [Name] => Poppy
)

Regards,
Greg
--
phpDocumentor
http://www.phpdoc.org

Alan D'Angelo wrote:
Hello,
In my PHP5 installation the first example print Poppy,
but the second return
Fatal error: Call to protected method dog::bark() from context '' in
c:\appserv\www\test\mailingphp50.php on line 18

In my previous installation oh PHP5, private variable worked well ...
PHP 5 is one beta, try with an next snapshot.


Alan



----- Original Message ----- From: "Paul Hudson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, July 11, 2003 11:21 PM
Subject: [PHP] Private and protected variables in PHP 5?




All,

I'm toying with the new stuff available in PHP 5 (latest CVS), but I've

hit a


brick wall: both private and protected don't seem to work as I'd expect

them


to.

Here's an example script:

<?php
 class dog {
   // declare two private variables
   private $Name;
   private $DogTag;

   public function bark() {
     print "Woof!\n";
   }
 }

 // new class, for testing derived stuff
 class poodle extends dog {
   public function bark() {
     print "Yip!\n";
   }
 }

 // I now create an instance of the
 // derived class
 $poppy = new poodle;

 // and set its private property
 $poppy->Name = "Poppy";
 print $poppy->Name;
?>

For some reason, that script works fine - PHP doesn't object to me setting
private variables in the derived class.  Yet if I use "$poppy = new dog",

the


script errors out as expected.  It's almost like PHP inherits the member
variables, but not the attached access control.

For protected, here's another script:

<?php
 class dog {
   // this next function is protected
   // viz, it should be available to dog
   // and its children

   protected function bark() {
     print "Woof!\n";
   }
 }

 class poodle extends dog {
   // nothing happening here
 }

 $mydog = new poodle;
 // I now call the protected function
 $mydog->bark();
?>

That script errors out saying that I can't call the protected function

bark -


surely, being protected, it should be available in the poodle class too?

Of course, it might be that these two pieces of functionality are not yet
implemented in PHP, or, more likely, that I'm just misinterpreting the
documentation! ;)

If you have any insight, please CC me into your response to the list.

Thanks,


Paul


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






--- End Message ---
--- Begin Message ---
First question: I'm creating a custom content manager for a small site. 
It will basically be used to store short articles (several paragraphs
each).  Now my question is, is storing these to a text file going to
work or am I going to have problems later on when the file gets to be a
reasonable size.  I ask this, because the only way I can seem to work
with the text file is to read the entire file in and alter it that way. 
Are there any ways to edit or remove one line of a text file without
having to read the entire file first?  Would I be better off using a
database instead of a text file (keep in mind that I know nothing about
databases)?

Question two: I've read in several books that html checkbox forms can
pass multiple values to the server when more than one check box is
selected if they have the same name.  However, when I var_dump the
$_POST variable that should contain them I only get one value.  Anyone
have any ideas why?

Regards,
Jason Giangrande


--- End Message ---
--- Begin Message ---
1. Text file or DB 
My answer -> Learn how to use a database, it will make things much
easier

2. Checkbox

Try this:

<input type="checkbox" name="sports[]" value="Baseball">
<input type="checkbox" name="sports[]" value="Basketball">
<input type="checkbox" name="sports[]" value="Football">
<input type="checkbox" name="sports[]" value="Handballball">

then after submission, you could do the dump, or

foreach ($_POST["sports"] as $val)
        echo $val;


On Fri, 2003-07-11 at 20:10, Jason Giangrande wrote:
> First question: I'm creating a custom content manager for a small
site. 
> It will basically be used to store short articles (several paragraphs
> each).  Now my question is, is storing these to a text file going to
> work or am I going to have problems later on when the file gets to be
a
> reasonable size.  I ask this, because the only way I can seem to work
> with the text file is to read the entire file in and alter it that
way. 
> Are there any ways to edit or remove one line of a text file without
> having to read the entire file first?  Would I be better off using a
> database instead of a text file (keep in mind that I know nothing
about
> databases)?
> 
> Question two: I've read in several books that html checkbox forms can
> pass multiple values to the server when more than one check box is
> selected if they have the same name.  However, when I var_dump the
> $_POST variable that should contain them I only get one value.  Anyone
> have any ideas why?
> 
> Regards,
> Jason Giangrande
> 


--- End Message ---
--- Begin Message ---
Thanks for your help guys.  The checkboxes thing is working great.

Michael, regarding using files instead of a database, in your opinion,
eventually having a 10-20 MB text file isn't going to cause any server
problems if more than a few people are accessing the site at a time? 
I'm not talking millions, or even thousands of users, more like a few
hundred a day.  If using files should not be a problem, I would much
rather use that method in this particular project.

Thanks again,
Jason

On Fri, 2003-07-11 at 21:27, Michael Smith wrote:
> Jason Giangrande wrote:
> > First question: I'm creating a custom content manager for a small site. 
> > It will basically be used to store short articles (several paragraphs
> > each).  Now my question is, is storing these to a text file going to
> > work or am I going to have problems later on when the file gets to be a
> > reasonable size.  I ask this, because the only way I can seem to work
> > with the text file is to read the entire file in and alter it that way. 
> > Are there any ways to edit or remove one line of a text file without
> > having to read the entire file first?  Would I be better off using a
> > database instead of a text file (keep in mind that I know nothing about
> > databases)?
> > 
> 
> Flat files are perfectly fine. If you include them with PHP there is 
> almost no performance hit. However, you could use file() to put them in 
> an array and then array_search to figure out which key and only use that ...
> 
> > Question two: I've read in several books that html checkbox forms can
> > pass multiple values to the server when more than one check box is
> > selected if they have the same name.  However, when I var_dump the
> > $_POST variable that should contain them I only get one value.  Anyone
> > have any ideas why?
> 
> the name attribute for the checkboxes needs to be name="somevar[]" to be 
> put in an array.
> 
> > 
> 
> 
> > Regards,
> > Jason Giangrande
> > 
> 
> Cheers,
> -Michael
> 
> > 
> 


--- End Message ---
--- Begin Message --- If that's the case I recommend using multiple files instead of one big. Just come up with some structure for them. I'd say 10-20MB text is pretty much.

//Simon

Jason Giangrande wrote:
Thanks for your help guys. The checkboxes thing is working great.

Michael, regarding using files instead of a database, in your opinion,
eventually having a 10-20 MB text file isn't going to cause any server
problems if more than a few people are accessing the site at a time? I'm not talking millions, or even thousands of users, more like a few
hundred a day. If using files should not be a problem, I would much
rather use that method in this particular project.


Thanks again,
Jason

On Fri, 2003-07-11 at 21:27, Michael Smith wrote:

Jason Giangrande wrote:

First question: I'm creating a custom content manager for a small site. It will basically be used to store short articles (several paragraphs
each). Now my question is, is storing these to a text file going to
work or am I going to have problems later on when the file gets to be a
reasonable size. I ask this, because the only way I can seem to work
with the text file is to read the entire file in and alter it that way. Are there any ways to edit or remove one line of a text file without
having to read the entire file first? Would I be better off using a
database instead of a text file (keep in mind that I know nothing about
databases)?



Flat files are perfectly fine. If you include them with PHP there is almost no performance hit. However, you could use file() to put them in an array and then array_search to figure out which key and only use that ...



Question two: I've read in several books that html checkbox forms can
pass multiple values to the server when more than one check box is
selected if they have the same name.  However, when I var_dump the
$_POST variable that should contain them I only get one value.  Anyone
have any ideas why?

the name attribute for the checkboxes needs to be name="somevar[]" to be put in an array.




Regards,
Jason Giangrande


Cheers, -Michael





--- End Message ---
--- Begin Message ---
Hi,

Saturday, July 12, 2003, 9:47:29 AM, you wrote:
JN> Hi!
JN> I want to know if anyone knows about a good mailing list manager that has
JN> got a PHP administration frontend

JN> I've found many PHP scripts for sending newsletters and announcementes, but
JN> that's it's not what I want
JN> I want a system like Mailman, Sympa or Majordomo (the mailing list server
JN> may be programmed in Perl or whatever), but it must provide a PHP frontend
JN> for administration, subscription, etc

JN> It would be great if messages are stored in a database like MySQL and it
JN> must be free software
JN> Does this exist??

JN> Thanks in advanced,

JN> Juan

I use Limez as the list server co existing with qmail (it does not use
qmail) works very well but not sure if any further development is
being done. Here is the url

http://www.limez.net/

-- 
regards,
Tom


--- End Message ---
--- Begin Message ---
Hi,

Saturday, July 12, 2003, 4:05:34 AM, you wrote:
J> How can I hide this link so value can't be changed?
J> I don't want to change anything at the server level, and its not from a 
J> form so I cant do a post -vs- a get.

J> http://www.abcd.com/SearchSet.php?searchby=cust_no&search=1&value=WOR032

J> Thanks !

Encrypt then base64_encode the query string before adding, that way
they can't stuff with it.

-- 
regards,
Tom


--- End Message ---
--- Begin Message --- What about sessions? Depends on your circumstances and the flow of pages, but storing all these vars in a session, then only passing the session id around in the URL could be an alternative

Justin

On Saturday, July 12, 2003, at 12:21 PM, Tom Rogers wrote:

Hi,

Saturday, July 12, 2003, 4:05:34 AM, you wrote:
J> How can I hide this link so value can't be changed?
J> I don't want to change anything at the server level, and its not from a
J> form so I cant do a post -vs- a get.


J> http://www.abcd.com/ SearchSet.php?searchby=cust_no&search=1&value=WOR032

J> Thanks !

Encrypt then base64_encode the query string before adding, that way
they can't stuff with it.

--
regards,
Tom


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

---
[This E-mail scanned for viruses]




--- End Message ---
--- Begin Message ---
Hi,

Saturday, July 12, 2003, 12:45:26 PM, you wrote:
JF> What about sessions?  Depends on your circumstances and the flow of  
JF> pages, but storing all these vars in a session, then only passing the  
JF> session id around in the URL could be an alternative

JF> Justin

Yes you can do it with sessions, but that may open a whole new
learning curve :)
For quick links I usually encode anything that maybe 'fiddled' with to
cause trouble.

-- 
regards,
Tom


--- End Message ---
--- Begin Message --- Wouldn't it be easier to use something like the following?

while (!feof ($handle)) {
    $buffer = fgets($handle, 4096);
    echo $buffer;
}

This will read until there's nothing more to read. Isn't that what you're trying to do?

Read more about it at http://se2.php.net/manual/en/function.fgets.php

//Simon

Seairth Jacobs wrote:
I have an open socket that I am reading from.  The code looks like the
following:

$contentLength = 0 + $this->response['headers']['content-length'];

do{
    $status = socket_get_status($this->socket);

    if( $status['eof'] == 1 ) {
        if( $this->clientOptions['debug'] & DBGSOCK ) echo("DBG.SOCK status
eof met, finished socket_read\n");
        break;
    }

if($status['unread_bytes'] > 0) {

        if($contentLength > $status['unread_bytes']) {
            echo("DBG.SOCK reading {$status['unread_bytes']} bytes...\n");
            $buffer = @fread($this->socket, $status['unread_bytes']);

            $contentLength = $contentLength - $status['unread_bytes'];
        } else {
            $buffer = @fread($this->socket, $contentLength);
            $contentLength = 0;
        }
    } else {
        if( $this->clientOptions['debug'] & DBGSOCK ) echo("DBG.SOCK reading
{$status['unread_bytes']} bytes...\n");
        usleep(1);
        continue;
    }

    $data .= $buffer;
} while($contentLength > 0);


Now, the above code hangs (infinite loop, actually), ultimately returning something like:

DBG.SOCK reading 3993 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
DBG.SOCK reading 0 bytes...
etc...

On the other hand, if I change the following lines:

$buffer = @fread($this->socket, $status['unread_bytes'] - 1);

$contentLength = $contentLength - $status['unread_bytes'] - 1;

Then I get something that looks like:

DBG.SOCK reading 3993 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
DBG.SOCK reading 1 bytes...
etc...

until the entire response has been read (88771 bytes in this case).  Also,
this would mean that the effective fread would be:

$buffer = @fread($this->socket, 0);

However, if I just do:

$data = @fread($this->socket, $contentLength);

it works as expected. So what's going on?

For now, I will use the single command in place of the loop, but I really
wanted to monitor the current unread bytes.  Any thoughts appreciated.

---
Seairth Jacobs
[EMAIL PROTECTED]




--- End Message ---
--- Begin Message ---
On Fri, Jul 11, 2003 at 02:21:42PM -0400, Phil Powell wrote:
>
> $booleanNonFormVars = array('hasSelectedLetter', 'hasEnteredProfile', 
> 'hasSelectedProfile',
...
>  $booleanVars = array('profileID', 'showemail', 'showbirthday', 'season', 
> 'profilememberid');
>  $profileVarArray = array('firstname', 'lastname', 'city', 'state', 'country', 
> 'favebands',
...
>  $profileNonFormVarArray = array('profileName', 'letter', 'name');
>  $arrayListArray = array('booleanNonFormVars', 'booleanVars', 'profileVarArray',
>                         'profileNonFormVarArray');
>
> Bluntly put, I need to get:
> $hasSelectedLetter
> $letter

What exactly are you hoping to get out of this?  What's suposed to be
the eventual content of the $hasSelectedLetter variable?  Are these
really how the arrays get set up, or is it really more like:

  $booleanNonFormVars = array(
    'hasSelectedLetter' => 'somevalue',
    'hasEnteredProfile' => 'anothervalue',
    ...                                   
  );

?
 
If so, you could take advantage of the fact that this is an interpreted
language, and do something like this:

  foreach ($booleanNonFormVars as $key => $value)  ${$key} = $value;
  foreach ($booleanVars        as $key => $value)  ${$key} = $value;
  foreach ($profileVarArray    as $key => $value)  ${$key} = $value;

etc.

Alternately, if $booleanNonFormVars are things for which you're just
trying to test existence, you could:

  foreach ($booleanNonFormVars as $value)  ${$value} = true;
  foreach ($booleanVars        as $value)  ${$value} = true;

Is either of these approaches what you're after?


--
  Paul Chvostek                                             <[EMAIL PROTECTED]>
  it.canada                                            http://www.it.ca/
  Free PHP web hosting!                            http://www.it.ca/web/


--- End Message ---
--- Begin Message ---
Hi there,

I am running PHP 4.3 something or other, I have enabled php_gd.dll and
php_gd2.dll, pointed the extension directory to the right place, looked at
the phpinfo and it has the correct information about the gd's being enabled,
I have tried reintalling apache and php...but still get errors on all simple
scripts that i have tried...

this is the error I get..

Fatal error: Call to undefined function: imagecreate()

any suggestions or tips?

Thank you!!!

Sincerely
Michelle



--- End Message ---
--- Begin Message ---
I have installed Apache 2.0.47 and php 4.3.2 in Windows 98. Downloaded the
php in the .zip format.

The Apache server works properly without the inclusion of php.
The problem is apache dosent even start with php in the SAPI mode,it gives a
error stating that:

"One of the device attached to the system isnt functioning properly"
(or)
"Library files missing"

and in the CGI mode the apache server starts and it executes the .html files
but it dosent execute the .php file or the .html files with php commands
giving an error statement:

"Internal Server Error
The server encountered an internal error or misconfiguration and was  unable
to complete your request."
with a dialog box message stating that
"The PHP4TS.DLL file is linked to missing export OLEAUT32.DLL:77."
(I do have the OLEAUT32.DLL file in the same folder as the PHP4TS.DLL file)

I have copied all the .dlls and php.ini to their respective places as given
in the manual but still dosent work.
I am hoping some one could give me a suggestion or a solution to my problem.



--- End Message ---

Reply via email to