|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
php-general-digest-help
lists.php.net
Date: Wed Jan 30 2008 - 12:30:05 CST
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
php-general Digest 30 Jan 2008 18:30:05 -0000 Issue 5265
Topics (messages 268304 through 268357):
Sum of results
268304 by: Dax Solomon Umaming
268307 by: Nathan Nobbe
Re: Timeout while waiting for a server->client transfer to start (large files)
268305 by: Chris
Re: Mysql session handler?
268306 by: Chris
Re: call to a member function select() on a non object.
268308 by: Jim Lucas
268311 by: Jochem Maas
Re: Need assistance using sendmail or mail()
268309 by: Per Jessen
268310 by: Nathan Nobbe
268312 by: Tom Chubb
Re: How can I do this -- method chaining
268313 by: Stut
268315 by: Jochem Maas
268316 by: Stut
268317 by: Jochem Maas
268318 by: Anup Shukla
268320 by: Jochem Maas
268323 by: Nathan Nobbe
268326 by: Stut
268327 by: Nathan Nobbe
268329 by: Stut
268330 by: Nathan Nobbe
268332 by: Stut
268333 by: Jim Lucas
268334 by: Nathan Nobbe
268335 by: Jim Lucas
268336 by: Stut
268337 by: Stut
268340 by: Nathan Nobbe
268341 by: Stut
268346 by: Jim Lucas
268347 by: Nathan Nobbe
268348 by: Stut
268349 by: Stut
268350 by: Nathan Nobbe
Re: php embeded in html after first submit html disappear
268314 by: Jochem Maas
Re: potentially __sleep() bug
268319 by: Anup Shukla
Re: Another question about functions...
268321 by: Jason Pruim
Re: first php 5 class
268322 by: Eric Butera
268324 by: Nathan Nobbe
268325 by: Eric Butera
268331 by: Nathan Nobbe
268338 by: Greg Donald
268339 by: Nathan Nobbe
268342 by: Eric Butera
268343 by: Eric Butera
268351 by: Greg Donald
268352 by: Zoltán Németh
268353 by: Nathan Nobbe
268354 by: Greg Donald
268356 by: Zoltán Németh
268357 by: Greg Donald
We need PHP/LAMP Developers and Programmers in FL, MD, VA, NY, DC, CA, MA!!!!
268328 by: PHP Employer
php spanish character problem
268344 by: greenCountry
268345 by: Eric Butera
Help looking for inventory software
268355 by: Zbigniew Szalbot
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscribe
lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscribe
lists.php.net
To post to the list, e-mail:
php-general
lists.php.net
----------------------------------------------------------------------
attached mail follows:
Hi;
I've tried Googling this out but failed to search for an answer to this, so
I'm posting to this list. I'd like to know if there's a way to get the sum
this results:
// Results
Individual Daily Consumption
//AccountNo : Consumption
4146121002: 1.42
4146111002: 0.29
4146113002: 1.38
4146110002: 0.33
4146112002: 0.00
4146118002: 9.96
== MORE ==
// Code that generated the results
while ($row6 = mysql_fetch_assoc($queryconsumerresults)) {
// Show Consumer AccountNo and their Consumption
echo $row6['AccountNo'] . ": " . sprintf("%1.2f", (((($row6['Reading'] +
$row6['KwHrAdjustment']) - ($row6['Reading1'] + $row6['KwHrAdjustment1'])) /
$noofdays) * $row6['Multiplier'])) . "<br />";
}
I've tried getting the sum() from the MySQL table, but Multiplier is either at
1 or 2 or 2.5 and the only way I can get an accurate total consumption is
getting the sum from the results.
Is there a way I can place this code on an array? I've tried using
$indcons = array( sprintf("%1.2f", (((($row6['Reading'] + $row6
['KwHrAdjustment']) - ($row6['Reading1'] + $row6['KwHrAdjustment1'])) /
$noofdays) * $row6['Multiplier']))) but I've obviously failed.
--
Dax Solomon Umaming
http://knightlust.com/
GPG: 0x715C3547
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQBHoCAI6Hw0ZHFcNUcRApgCAKDA4gNzm06FNWaJDazi9IVO16ckqgCgu8Ck
/N/+T7ATqBUGzKlkiY4ZN8I=
=shfI
-----END PGP SIGNATURE-----
attached mail follows:
On Jan 30, 2008 1:58 AM, Dax Solomon Umaming <knightlust
gmail.com> wrote:
> I've tried Googling this out but failed to search for an answer to this, so
> I'm posting to this list. I'd like to know if there's a way to get the sum
> this results:
you can simply sum them as you print the report
$sum = 0.0;
while ($row6 = mysql_fetch_assoc($queryconsumerresults)) {
$curVal = ((($row6['Reading'] + $row6['KwHrAdjustment']) -
($row6['Reading1'] + $row6['KwHrAdjustment1'])) / $noofdays) *
$row6['Multiplier']));
// Show Consumer AccountNo and their Consumption
echo $row6['AccountNo'] . ": " . sprintf("%1.2f", ( $curVal . "<br />";
// add curVal to sum
$sum += $curVal;
}
> Is there a way I can place this code on an array? I've tried using
> $indcons = array( sprintf("%1.2f", (((($row6['Reading'] + $row6
> ['KwHrAdjustment']) - ($row6['Reading1'] + $row6['KwHrAdjustment1'])) /
> $noofdays) * $row6['Multiplier']))) but I've obviously failed.
array() creates an array, what youve done on this line is created
an array with one element, which will be the last value of $row6 from the while
loop that precedes it. since the last value returned from mysql_fetch_assoc()
is false (thats what terminates the while loop), im guessing $indcons contains
false as its only value.
if you want to place these values in an array as you iterate over them, add this
inside the while loop:
$indcons[] = $curVal;
-nathan
attached mail follows:
Barney Tramble wrote:
>
> Hey
>
> I have a script that I am trying to figure out to allow a remote file to
> be sent to a client's browser. It works ok for small files, but it keeps
> timing out for large files. I don't think it should even take as long as
> it does (i.e. about 10seconds) before it pops up a dialog box for me to
> download a 700KB file. Any ideas? It times out on a line around which reads
>
> while (!feof($fp))
> {
> $tmp .= fread($fp, 64);
> }
Well you're still reading the file (or url or something) at this point.
Is it the reading of the file or sending it to the browser that fails?
A bit of context might help for this code too. Is this reading a local
file or url or what?
If it's a local file, use fpassthru (http://php.net/fpassthru) if it's
not too big. If it is a big file then use your loop but don't store it
in a $tmp variable, just output it.
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
Mike Yrabedra wrote:
> Can anyone recommend a good php-mysql session handler class?
http://www.php.net/manual/en/function.session-set-save-handler.php#79706
looks ok.
--
Postgresql & php tutorials
http://www.designmagick.com/
attached mail follows:
nihilism machine wrote:
> // Connect to the database
> public function __construct() {
> $DB = new db();
Everything Nathan said, plus change the $DB to $this->DB in your
construct() method.
Jim
attached mail follows:
you already had the answer to this problem. do try to read the error message properly.
a 'non object' is quite clear - if in doubt about what something is or something
should be use var_dump() or print_r() to output the variable in question (e.g. $DB, which
you would have seen was NULL).
now for some tips ...
nihilism machine schreef:
> I amn trying to use my db class in my auth class, but i get the error:
> call to a member function select() on a non object
>
> <?php
>
> class db {
>
> // Members
> private $db_user = "mydbuser";
> private $db_pass = "mypassword";
> private $db_name = "mydb";
> private $db_server = "myhost.com";
don't store these in the class - it makes the class usable
only for 1 explicit project/DB, and classes are supposed to
be reusable.
instead pass in these connection parameters to the constructor
(or something similar)
> private $link;
> private $result_id;
>
> // Methods
> public function __construct() {
> $this->connect();
> }
>
> // Connect to MySQL Server
> private function connect() {
> $this->link =
> mysql_connect($this->db_server,$this->db_user,$this->db_pass) or
> die("ERROR - Cannot Connect to DataBase");
> mysql_select_db($this->db_name,$this->link) or die("ERROR:
> Cannot Select Database (" . $this->db_name . ")");
the 'or die("bla bla");' type of error handling is rubbish, you can
use it for simple/throw-away scripts but when your writing a class
you should make the error handling much more flexible and leave it
up to the code that uses the class to decide how to handle the
error. with the die() statement the consumer of the class has no choice
about what to do if a connection error occurs.
> }
>
> // Disconnect from MySQL Server
> private function disconnect() {
> mysql_close($this->link);
> }
>
> // MySQL Select
> public function select($sql) {
> $this->result_id = $this->query($sql);
> if($this->result_id){
> $rows = $this->fetch_rows();
> }
> return $rows;
your returning $rows even if it was not created, this gives you an
E_NOTICE error when you don't get a result id back.
> }
>
> // Insert into MySQL
> public function insert($params) {
> extract($params);
I wouldn't use extract, also your not doing any input parameter checking here.
> $sql = 'INSERT INTO '.$table.' ('.$fields.') VALUES ('.$values.')';
the preceding line has SQL injection potential written all over it.
> $this->query($sql);
> if($this->result_id){
> $affected_rows = $this->affected_rows();
> }
> return $affected_rows;
> }
>
> // Delete from MySQL
> public function delete($params) {
> extract($params);
> $sql = 'DELETE FROM '.$table.' WHERE '.$where;
> if (is_numeric($limit)) {
> $sql .= ' LIMIT '.$limit;
> }
> $this->query($sql);
> if($this->result_id){
> $affected_rows = $this->affected_rows();
> }
> return $affected_rows;
> }
>
> // Update MySQL
> public function update($params) {
> extract($params);
> $sql = 'UPDATE '.$table.' SET '.$values.' WHERE '.$where;
> if(is_numeric($limit)){
> $sql .= ' LIMIT '.$limit;
> }
> $this->query($sql);
> if($this->result_id){
> $affected_rows = $this->affected_rows();
> }
> return $affected_rows;
> }
>
> // MySQL Query
> private function query($sql) {
> $this->result_id = mysql_query($sql);
> return $this->fetch_rows();
> }
>
>
> // MySQL Fetch Rows
> private function fetch_rows() {
> $rows = array();
> if($this->result_id){
> while($row = mysql_fetch_object($this->result_id)){
> $rows[] = $row;
> }
> }
> return $rows;
> }
>
> // MySQL Affected Rows
> private function affected_rows() {
> return mysql_affected_rows($this->link);
> }
>
> // MySQL Affected Rows
> private function num_rows() {
> return mysql_num_rows($this->link);
> }
>
> // MySQL Affected Rows
> private function select_id() {
> return mysql_insert_id($this->link);
> }
>
> // Destruct!
> public function __destruct() {
> $this->disconnect();
> }
> }
>
> ?>
>
>
>
> <?php
>
> require_once("db.class.php");
>
> class auth {
>
> public $DB;
> public $UserID;
> public $AdminLevel;
> public $FirstName;
> public $LastName;
> public $DateAdded;
> public $MobileTelephone;
> public $LandLineTelephone;
public members suck.
>
> // Connect to the database
> public function __construct() {
> $DB = new db();
how many objects will be using a DB connection? will each one be
using a new copy? consider passing in a DB object, that way your
saving having to create one each time.
> }
>
> // Attempt to login a user
> public function CheckValidUser($Email, $Password) {
> $PasswordEncoded = $this->encode($Password);
> $rows = $DB->select("SELECT * Users WHERE Email='$Email', AND
> Password='$PasswordEncoded'");
again SQL injection potential, at the very least you should be
using mysql_real_escape_string();
> if ($DB->num_rows > 0) {
> $this->UserID = $row['ID'];
> $this->AdminLevel = $row['Admin_Level'];
> $this->FirstName = $row['First_Name'];
> $this->LastName = $row['Last_Name'];
> $this->DateAdded = $row['Date_Added'];
> $this->MobileTelephone = $row['Telephone_Mobile'];
> $this->LandLineTelephone = $row['Telephone_Land_Line'];
> // User info stored in Sessions
> session_start();
> $_SESSION['Status'] = "loggedIn";
> $_SESSION['ID'] = $row['ID'];
> $_SESSION['Email'] = $row['Email'];
> $_SESSION['AdminLevel'] = $row['Admin_Level'];
> $_SESSION['LandLine'] = $row['Telephone_Land_Line'];
> $_SESSION['MobileTelephone'] = $row['Telephone_Mobile'];
> $_SESSION['FirstName'] = $row['First_Name'];
> $_SESSION['LastName'] = $row['Last_Name'];
here your only storing the values in the Auth object during the request
that the check for a valid user is done. subsequent requests will have
no values for Auth->UserID (et al). which begs the question: why bother to
have these member properties at all?
> } else {
> return false;
> }
> }
>
> public function encode($str) {
> return md5(base64_encode($str));
> }
> }
>
> ?>
>
> <?php
>
> $myauth = new auth();
> $x = $myauth->CheckValidUser("test
test.com", "password");
> echo $x;
>
> ?>
>
attached mail follows:
philip wrote:
> Hi everyone,
>
> I need assistance using sendmail or mail() as my web hosting service
> does not allow opening sockets.
>
> This is the code I use:
Philip, please state what sort of problems you are having. mail() and
sendmail are both easy to use from php.
And please don't post another 2000 lines of code. No-one is going to
read them.
/Per Jessen, ZĂźrich
attached mail follows:
On Jan 30, 2008 2:47 AM, Per Jessen <per
computer.org> wrote:
> Philip, please state what sort of problems you are having. mail() and
> sendmail are both easy to use from php.
> And please don't post another 2000 lines of code. No-one is going to
> read them.
amen to that brother! :)
-nathan
attached mail follows:
On 30/01/2008, Per Jessen <per
computer.org> wrote:
>
> philip wrote:
>
> > Hi everyone,
> >
> > I need assistance using sendmail or mail() as my web hosting service
> > does not allow opening sockets.
> >
> > This is the code I use:
>
> Philip, please state what sort of problems you are having. mail() and
> sendmail are both easy to use from php.
> And please don't post another 2000 lines of code. No-one is going to
> read them.
>
>
>
> /Per Jessen, Zürich
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
He's just trying to get a nice share of the bytes on Dan's weekly posting
summary ;)
attached mail follows:
Nathan Nobbe wrote:
> On Jan 29, 2008 7:27 PM, Stut <stuttle
gmail.com> wrote:
>> Personally I'd use a static method in this instance.
>
> thats what i recommended.
>
>> If you need to create
>> an instance of the class you can do so in the static method and that way it
>> will get destroyed when the function is done. Otherwise the object scope is
>> far larger than it needs to be, which IMHO is an unnecessary waste of
>> resources and certainly less aesthetic.
>
> lost you on this part ..
> whether you create an instance in client code by calling new or
> encapsulate the call
> to new in a simple factory method there will still be only one
> instance of the class,
> and it will still be in scope once the method is finished executing,
> because all it does
> is return an instance of the class its a member of.
> maybe you mean something other than what i posted earlier when you say
> static method?
You posted a singleton pattern. That means that from the moment you call
the static method until the end of the script that object exists. That's
probably fine for web-based scripts that don't run for long, but I live
in a world where classes often get used in unexpected ways so I tend to
write code that's efficient without relying on the environment it's
running in to clean it up.
This was your code...
<?php
class Test {
public static function getInstance() {
return new Test();
}
public function doSomething() {
echo __METHOD__ . PHP_EOL;
}
}
Test::getInstance()->doSomething();
?>
This would be my implementation...
<?php
class Test {
public static function doSomething() {
$o = new Test();
$o->_doSomething();
}
protected function _doSomething() {
// I'm assuming this method is fairly complex, and involves
// more than just this method, otherwise there is no point
// in creating an instance of the class, just use a static
// method.
}
}
Test::doSomething();
?>
Of course this is just based on what the OP said they wanted to do. If
there is no reason to create an instance of the object then don't do it.
It's fairly likely that I'd actually just use a static method here, but
it depends on what it's actually doing.
But as I said earlier, each to their own.
-Stut
--
http://stut.net/
attached mail follows:
Stut schreef:
> Nathan Nobbe wrote:
>> On Jan 29, 2008 7:27 PM, Stut <stuttle
gmail.com> wrote:
>>> Personally I'd use a static method in this instance.
>>
>> thats what i recommended.
>>
>>> If you need to create
>>> an instance of the class you can do so in the static method and that
>>> way it
>>> will get destroyed when the function is done. Otherwise the object
>>> scope is
>>> far larger than it needs to be, which IMHO is an unnecessary waste of
>>> resources and certainly less aesthetic.
>>
>> lost you on this part ..
>> whether you create an instance in client code by calling new or
>> encapsulate the call
>> to new in a simple factory method there will still be only one
>> instance of the class,
>> and it will still be in scope once the method is finished executing,
>> because all it does
>> is return an instance of the class its a member of.
>> maybe you mean something other than what i posted earlier when you say
>> static method?
>
> You posted a singleton pattern.
huh? the OPs getInstance() method returns a new object on each call, hardly
a singleton is it?
That means that from the moment you call
> the static method until the end of the script that object exists. That's
> probably fine for web-based scripts that don't run for long, but I live
> in a world where classes often get used in unexpected ways so I tend to
> write code that's efficient without relying on the environment it's
> running in to clean it up.
are you saying that the OPs getInstance() method causes each new instance
to hang around inside memory because php doesn't know that it's no longer referenced,
even when it's used like so:
Test::getInstance()->doSomething();
and that your alternative does allow php to clean up the memory?
>
> This was your code...
>
> <?php
> class Test {
> public static function getInstance() {
> return new Test();
> }
>
> public function doSomething() {
> echo __METHOD__ . PHP_EOL;
> }
> }
> Test::getInstance()->doSomething();
> ?>
>
> This would be my implementation...
>
> <?php
> class Test {
> public static function doSomething() {
> $o = new Test();
> $o->_doSomething();
> }
>
> protected function _doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
> }
> }
> Test::doSomething();
> ?>
>
> Of course this is just based on what the OP said they wanted to do. If
> there is no reason to create an instance of the object then don't do it.
> It's fairly likely that I'd actually just use a static method here, but
> it depends on what it's actually doing.
>
> But as I said earlier, each to their own.
>
> -Stut
>
attached mail follows:
Jochem Maas wrote:
> Stut schreef:
>> Nathan Nobbe wrote:
>>> On Jan 29, 2008 7:27 PM, Stut <stuttle
gmail.com> wrote:
>>>> Personally I'd use a static method in this instance.
>>>
>>> thats what i recommended.
>>>
>>>> If you need to create
>>>> an instance of the class you can do so in the static method and that
>>>> way it
>>>> will get destroyed when the function is done. Otherwise the object
>>>> scope is
>>>> far larger than it needs to be, which IMHO is an unnecessary waste of
>>>> resources and certainly less aesthetic.
>>>
>>> lost you on this part ..
>>> whether you create an instance in client code by calling new or
>>> encapsulate the call
>>> to new in a simple factory method there will still be only one
>>> instance of the class,
>>> and it will still be in scope once the method is finished executing,
>>> because all it does
>>> is return an instance of the class its a member of.
>>> maybe you mean something other than what i posted earlier when you say
>>> static method?
>>
>> You posted a singleton pattern.
>
> huh? the OPs getInstance() method returns a new object on each call, hardly
> a singleton is it?
Quite right too. Didn't read it properly.
> That means that from the moment you call
>> the static method until the end of the script that object exists.
>> That's probably fine for web-based scripts that don't run for long,
>> but I live in a world where classes often get used in unexpected ways
>> so I tend to write code that's efficient without relying on the
>> environment it's running in to clean it up.
>
> are you saying that the OPs getInstance() method causes each new instance
> to hang around inside memory because php doesn't know that it's no
> longer referenced,
> even when it's used like so:
>
> Test::getInstance()->doSomething();
>
> and that your alternative does allow php to clean up the memory?
I could be wrong, I don't know the internals of PHP well enough to be
definitive, but I'd rather err on the side of caution than write leaky code.
-Stut
--
http://stut.net/
attached mail follows:
Stut schreef:
> Jochem Maas wrote:
>> Stut schreef:
>>> Nathan Nobbe wrote:
>>>> On Jan 29, 2008 7:27 PM, Stut <stuttle
gmail.com> wrote:
>>>>> Personally I'd use a static method in this instance.
>>>>
>>>> thats what i recommended.
>>>>
>>>>> If you need to create
>>>>> an instance of the class you can do so in the static method and
>>>>> that way it
>>>>> will get destroyed when the function is done. Otherwise the object
>>>>> scope is
>>>>> far larger than it needs to be, which IMHO is an unnecessary waste of
>>>>> resources and certainly less aesthetic.
>>>>
>>>> lost you on this part ..
>>>> whether you create an instance in client code by calling new or
>>>> encapsulate the call
>>>> to new in a simple factory method there will still be only one
>>>> instance of the class,
>>>> and it will still be in scope once the method is finished executing,
>>>> because all it does
>>>> is return an instance of the class its a member of.
>>>> maybe you mean something other than what i posted earlier when you say
>>>> static method?
>>>
>>> You posted a singleton pattern.
>>
>> huh? the OPs getInstance() method returns a new object on each call,
>> hardly
>> a singleton is it?
>
> Quite right too. Didn't read it properly.
>
>> That means that from the moment you call
>>> the static method until the end of the script that object exists.
>>> That's probably fine for web-based scripts that don't run for long,
>>> but I live in a world where classes often get used in unexpected ways
>>> so I tend to write code that's efficient without relying on the
>>> environment it's running in to clean it up.
>>
>> are you saying that the OPs getInstance() method causes each new instance
>> to hang around inside memory because php doesn't know that it's no
>> longer referenced,
>> even when it's used like so:
>>
>> Test::getInstance()->doSomething();
>>
>> and that your alternative does allow php to clean up the memory?
>
> I could be wrong, I don't know the internals of PHP well enough to be
> definitive, but I'd rather err on the side of caution than write leaky
> code.
the way I understand garbage collection as it is right now is that pretty much
nothing is cleaned up until the end of the request but that php should be able
to see that the ref count is zero in both cases either way.
IIUC the yet to be released garbage collection improvements will potentially find/destroy
unused zvals sooner (as well as being better in sorting out defunct circular references etc)
but that the garbage collection itself uses a certain ammount of cpu cycles and in short
running scripts (e.g. most of what we write for the web) it's likely to be better to
let php just destroy memory at the end of the request.
that said your more cautious approach cannot hurt :-)
PS - my apologies if the memory related terminology I've used is somewhat bogus - please
put it down to my lack of proper understanding :-/
>
> -Stut
>
attached mail follows:
Nathan Nobbe wrote:
>> Actually, I don't think so. I believe constructors return void, while
>> the 'new' keyword returns a copy of the object.
>
>
> im pretty sure constructors return an object instance:
> php > class Test { function __construct() {} }
> php > var_dump(new Test());
> object(Test)#1 (0) {
> }
>
AFAIK, constructor simply constructs the object,
and *new* is the one that binds the reference to the variable
on the lhs.
So, constructors return nothing.
> but anyway, how could you even test that __construct() returned void
> and the new keyword returned a copy of the object? new essentially
> invokes __construct() and passes along its return value, near as i can tell.
>
> Christoph,
> if you dont want to write a function in the global namespace, as suggested
> in the article, Eric posted, just add a simple factory method in your class,
> eg.
> <?php
> class Test {
> public static function getInstance() {
> return new Test();
> }
>
> public function doSomething() {
> echo __METHOD__ . PHP_EOL;
> }
> }
> Test::getInstance()->doSomething();
> ?>
>
> -nathan
>
--
Regards,
Anup Shukla
attached mail follows:
Anup Shukla schreef:
> Nathan Nobbe wrote:
>>> Actually, I don't think so. I believe constructors return void, while
>>> the 'new' keyword returns a copy of the object.
>>
>>
>> im pretty sure constructors return an object instance:
>> php > class Test { function __construct() {} }
>> php > var_dump(new Test());
>> object(Test)#1 (0) {
>> }
>>
>
> AFAIK, constructor simply constructs the object,
> and *new* is the one that binds the reference to the variable
> on the lhs.
not exactly - 'new' asks php to initialize an object of the given class,
the 'binding' to a variable occurs because of the assignment operator. the __construct()
method is called automatically by php after the object structure has been initialized, so primarily
nothing is returned because the call to __construct() doesn't happen directly in userland code.
at least that's how I understand it.
>
> So, constructors return nothing.
>
>> but anyway, how could you even test that __construct() returned void
>> and the new keyword returned a copy of the object? new essentially
>> invokes __construct() and passes along its return value, near as i can
>> tell.
>>
>> Christoph,
>> if you dont want to write a function in the global namespace, as
>> suggested
>> in the article, Eric posted, just add a simple factory method in your
>> class,
>> eg.
>> <?php
>> class Test {
>> public static function getInstance() {
>> return new Test();
>> }
>>
>> public function doSomething() {
>> echo __METHOD__ . PHP_EOL;
>> }
>> }
>> Test::getInstance()->doSomething();
>> ?>
>>
>> -nathan
>>
>
>
attached mail follows:
On Jan 30, 2008 5:56 AM, Stut <stuttle
gmail.com> wrote:
> Nathan Nobbe wrote:
> You posted a singleton pattern.
no, what i posted was a simple factory pattern.
if you invoke it twice there will be 2 instances of Test in memory,
eg. not singleton.
$a = Test::getInstance();
$b = Test::getInstance();
> That means that from the moment you call
> the static method until the end of the script that object exists. That's
> probably fine for web-based scripts that don't run for long, but I live
> in a world where classes often get used in unexpected ways so I tend to
> write code that's efficient without relying on the environment it's
> running in to clean it up.
i usually only need to do cleanup in cli scripts that batch large amounts of
data. this is my practical experience anyway.
> This would be my implementation...
>
> <?php
> class Test {
> public static function doSomething() {
> $o = new Test();
> $o->_doSomething();
> }
>
> protected function _doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
> }
> }
> Test::doSomething();
> ?>
>
> Of course this is just based on what the OP said they wanted to do. If
> there is no reason to create an instance of the object then don't do it.
well you are still creating an instance of the object. the only difference
is
you are forcing it the ref count to 0 by assigning the instance to a local
local variable.
It's fairly likely that I'd actually just use a static method here,
both your and my code use static methods. it sounds to me like you are
using the term 'static method' to mean a static method that has a variable
with a reference to an instance of the class that it is a member of. which
is obviously a particular use of a static method, and therefore a bad
practice
imho. not the technique, mind you, the label of 'static method' for the
technique.
-nathan
attached mail follows:
Nathan Nobbe wrote:
>> It's fairly likely that I'd actually just use a static method here,
>
> both your and my code use static methods. it sounds to me like you are
> using the term 'static method' to mean a static method that has a variable
> with a reference to an instance of the class that it is a member of. which
> is obviously a particular use of a static method, and therefore a bad
> practice
> imho. not the technique, mind you, the label of 'static method' for the
> technique.
Actually no, I mean I would *just* use a static method. If there is no
reason to instantiate an object, why would you?
-Stut
--
http://stut.net/
attached mail follows:
On Jan 30, 2008 10:46 AM, Stut <stuttle
gmail.com> wrote:
> Nathan Nobbe wrote:
>
> Actually no, I mean I would *just* use a static method. If there is no
> reason to instantiate an object, why would you? <http://stut.net/>
you realize you are instantiating an class in the code you posted, right?
from you post:
$o = new Test();
if i didnt know any better, id call that an instantiation of the Test class
;)
the only thing is you are forcing it out of scope by using a local variable
to store the reference to the object.
-nathan
attached mail follows:
Nathan Nobbe wrote:
> On Jan 30, 2008 10:46 AM, Stut <stuttle
gmail.com
> <mailto:stuttle
gmail.com>> wrote:
>
> Nathan Nobbe wrote:
>
> Actually no, I mean I would *just* use a static method. If there is no
> reason to instantiate an object, why would you? <http://stut.net/>
>
>
> you realize you are instantiating an class in the code you posted, right?
> from you post:
> $o = new Test();
> if i didnt know any better, id call that an instantiation of the Test
> class ;)
> the only thing is you are forcing it out of scope by using a local variable
> to store the reference to the object.
Seriously? You really need to read the emails you're replying to. I gave
an example that did what the OP asked for. Then I went on to say that I
would probably just use a static method. I never said I wasn't creating
an instance in the example I posted.
The "forcing it out of scope" was the crux of my point. However, if
Jochem is right then it's kinda pointless with the current
implementation of the GC, but may become relevant in the new GC.
-Stut
--
http://stut.net/
attached mail follows:
On Jan 30, 2008 10:53 AM, Stut <stuttle
gmail.com> wrote:
> Nathan Nobbe wrote:
> I never said I wasn't creating
> an instance in the example I posted.
>
then what exactly did you mean by this?
Actually no, I mean I would *just* use a static method. If there is no
reason to instantiate an object, why would you?
-nathan
attached mail follows:
Nathan Nobbe wrote:
> On Jan 30, 2008 10:53 AM, Stut <stuttle
gmail.com
> <mailto:stuttle
gmail.com>> wrote:
>
> Nathan Nobbe wrote:
> I never said I wasn't creating
> an instance in the example I posted.
>
>
> then what exactly did you mean by this?
>
> Actually no, I mean I would *just* use a static method. If there is no
> reason to instantiate an object, why would you?
I meant "I would *just* use a static method". Calling a static method
does not create an instance of the class. My comments usually follow the
rule of Ronseal.
What do you think I meant by it?
-Stut
--
http://stut.net/
attached mail follows:
Stut wrote:
> Nathan Nobbe wrote:
>> On Jan 30, 2008 10:53 AM, Stut <stuttle
gmail.com
>> <mailto:stuttle
gmail.com>> wrote:
>>
>> Nathan Nobbe wrote:
>> I never said I wasn't creating
>> an instance in the example I posted.
>>
>>
>> then what exactly did you mean by this?
>>
>> Actually no, I mean I would *just* use a static method. If there is no
>> reason to instantiate an object, why would you?
>
> I meant "I would *just* use a static method". Calling a static method
> does not create an instance of the class. My comments usually follow the
> rule of Ronseal.
>
> What do you think I meant by it?
>
> -Stut
>
From your previous email
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
On Jan 30, 2008 11:21 AM, Stut <stuttle
gmail.com> wrote:
> Calling a static method
> does not create an instance of the class.
there you go again; calling a static method does create an instance of
the class if you call new inside of it :P
-nathan
attached mail follows:
Stut wrote:
> Nathan Nobbe wrote:
>> On Jan 30, 2008 10:53 AM, Stut <stuttle
gmail.com
>> <mailto:stuttle
gmail.com>> wrote:
>>
>> Nathan Nobbe wrote:
>> I never said I wasn't creating
>> an instance in the example I posted.
>>
>>
>> then what exactly did you mean by this?
>>
>> Actually no, I mean I would *just* use a static method. If there is no
>> reason to instantiate an object, why would you?
>
> I meant "I would *just* use a static method". Calling a static method
> does not create an instance of the class. My comments usually follow the
> rule of Ronseal.
>
> What do you think I meant by it?
>
> -Stut
>
From your previous email
<?php
class Test {
public static function doSomething() {
$o = new Test();
The above line IS creating a instance of the class Test
Now with proper garbage collection, it should be wiped out when you are done
using the static doSomething() method.
$o->_doSomething();
You could always include this to remove the instance of class Test
unset($o);
}
protected function _doSomething() {
// I'm assuming this method is fairly complex, and involves
// more than just this method, otherwise there is no point
// in creating an instance of the class, just use a static
// method.
}
}
Test::doSomething();
?>
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
Nathan Nobbe wrote:
> On Jan 30, 2008 11:21 AM, Stut <stuttle
gmail.com
> <mailto:stuttle
gmail.com>> wrote:
>
> Calling a static method
> does not create an instance of the class.
>
>
> there you go again; calling a static method does create an instance of
> the class if you call new inside of it :P
FFS, are you just trolling?
Note that I actually wrote "*just* a static method", and I stated quite
clearly that it was what I would do and that the code I posted was
providing what the OP wanted. If you can't see the separation then I'm
done with trying to convince you.
-Stut
--
http://stut.net/
attached mail follows:
Jim Lucas wrote:
> Stut wrote:
>> Nathan Nobbe wrote:
>>> On Jan 30, 2008 10:53 AM, Stut <stuttle
gmail.com
>>> <mailto:stuttle
gmail.com>> wrote:
>>>
>>> Nathan Nobbe wrote:
>>> I never said I wasn't creating
>>> an instance in the example I posted.
>>>
>>>
>>> then what exactly did you mean by this?
>>>
>>> Actually no, I mean I would *just* use a static method. If there is no
>>> reason to instantiate an object, why would you?
>>
>> I meant "I would *just* use a static method". Calling a static method
>> does not create an instance of the class. My comments usually follow
>> the rule of Ronseal.
>>
>> What do you think I meant by it?
>>
>> -Stut
>>
>
> From your previous email
>
>
> <?php
> class Test {
> public static function doSomething() {
> $o = new Test();
>
> The above line IS creating a instance of the class Test
>
> Now with proper garbage collection, it should be wiped out when you are
> done using the static doSomething() method.
>
> $o->_doSomething();
>
> You could always include this to remove the instance of class Test
>
> unset($o);
>
>
> }
>
> protected function _doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
> }
> }
> Test::doSomething();
> ?>
"I would *just* use a static method"
*just* *just* *just* *just* *just* *just* *just* *just* *just*
No instance. None. Grrr.
FFS.
-Stut
--
http://stut.net/
attached mail follows:
On Jan 30, 2008 11:31 AM, Stut <stuttle
gmail.com> wrote:
>
> "I would *just* use a static method"
>
> *just* *just* *just* *just* *just* *just* *just* *just* *just*
>
> No instance. None. Grrr.
here is a mod of the code you posted w/ a var_dump() of the
local variable $o;
<?php
class Test {
public static function doSomething() {
$o = new Test();
var_dump($o);
$o->_doSomething();
}
protected function _doSomething() {
// I'm assuming this method is fairly complex, and involves
// more than just this method, otherwise there is no point
// in creating an instance of the class, just use a static
// method.
}
}
Test::doSomething();
?>
nathan
gentooss ~/ticketsDbCode $ php testCode.php
object(Test)#1 (0) {
}
clearly in the act of *just* using a static method, you *just*
created an instance of class Test ;)
-nathan
attached mail follows:
Nathan Nobbe wrote:
> On Jan 30, 2008 11:31 AM, Stut <stuttle
gmail.com
> <mailto:stuttle
gmail.com>> wrote:
>
>
> "I would *just* use a static method"
>
> *just* *just* *just* *just* *just* *just* *just* *just* *just*
>
> No instance. None. Grrr.
>
>
> here is a mod of the code you posted w/ a var_dump() of the
> local variable $o;
>
> <?php
> class Test {
> public static function doSomething() {
> $o = new Test();
> var_dump($o);
> $o->_doSomething();
> }
>
> protected function _doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
> }
> }
> Test::doSomething();
> ?>
>
> nathan
gentooss ~/ticketsDbCode $ php testCode.php
> object(Test)#1 (0) {
> }
>
>
> clearly in the act of *just* using a static method, you *just*
> created an instance of class Test ;)
Ok, I'm going to have to assume you really are as stupid as you seem. If
I need to provide an example to demonstrate what I meant I will, but I
feel I made it quite clear that my comment regarding what *I* would do
did not in any way relate to the code example I had provided above. The
example I provided was fulfilling the OP's requirements.
This is what *I* would do...
<?php
class Test {
public static function doSomething() {
// I'm assuming this method is fairly complex, and involves
// more than just this method, otherwise there is no point
// in creating an instance of the class, just use a static
// method.
// ^^^^ See this comment here, this was taken from the
// non-static method in the example I posted. This is what
// I meant when I say "just use a static method".
}
}
Test::doSomething();
?>
Look ma, no instance.
FYI I'm not at all new to OOP, in general or in PHP, so I am well aware
that the example I originally posted created an instance of the class.
-Stut
--
http://stut.net/
attached mail follows:
Stut wrote:
> Nathan Nobbe wrote:
>> On Jan 30, 2008 11:31 AM, Stut <stuttle
gmail.com
>> <mailto:stuttle
gmail.com>> wrote:
>>
>>
>> "I would *just* use a static method"
>>
>> *just* *just* *just* *just* *just* *just* *just* *just* *just*
>>
>> No instance. None. Grrr.
>>
>>
>> here is a mod of the code you posted w/ a var_dump() of the
>> local variable $o;
>>
>> <?php
>> class Test {
>> public static function doSomething() {
>> $o = new Test();
>> var_dump($o);
>> $o->_doSomething();
>> }
>>
>> protected function _doSomething() {
>> // I'm assuming this method is fairly complex, and involves
>> // more than just this method, otherwise there is no point
>> // in creating an instance of the class, just use a static
>> // method.
>> }
>> }
>> Test::doSomething();
>> ?>
>>
>> nathan
gentooss ~/ticketsDbCode $ php testCode.php
>> object(Test)#1 (0) {
>> }
>>
>>
>> clearly in the act of *just* using a static method, you *just*
>> created an instance of class Test ;)
>
> Ok, I'm going to have to assume you really are as stupid as you seem. If
> I need to provide an example to demonstrate what I meant I will, but I
> feel I made it quite clear that my comment regarding what *I* would do
> did not in any way relate to the code example I had provided above. The
> example I provided was fulfilling the OP's requirements.
>
> This is what *I* would do...
>
> <?php
> class Test {
> public static function doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
>
> // ^^^^ See this comment here, this was taken from the
> // non-static method in the example I posted. This is what
> // I meant when I say "just use a static method".
> }
> }
> Test::doSomething();
> ?>
>
> Look ma, no instance.
Now this is clear.
But to point out in the code I quoted, you said that you were going to only use
the static method, but you were calling the static method that created an
instance of the Test class and then calling the non-static method from the
instance of the Test class.
Your previous example was not showing us what you were saying. To me it looked
like you were confused about how you were calling/creating things.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare
attached mail follows:
On Jan 30, 2008 11:58 AM, Stut <stuttle
gmail.com> wrote:
> Ok, I'm going to have to assume you really are as stupid as you seem. If
> I need to provide an example to demonstrate what I meant I will, but I
> feel I made it quite clear that my comment regarding what *I* would do
> did not in any way relate to the code example I had provided above. The
> example I provided was fulfilling the OP's requirements.
>
> This is what *I* would do...
>
> <?php
> class Test {
> public static function doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
>
> // ^^^^ See this comment here, this was taken from the
> // non-static method in the example I posted. This is what
> // I meant when I say "just use a static method".
> }
> }
> Test::doSomething();
> ?>
>
> Look ma, no instance.
>
well, at least its clear now, what you meant.
> FYI I'm not at all new to OOP, in general or in PHP, so I am well aware
> that the example I originally posted created an instance of the class.
glad to hear it; no hard feelings i hope..
-nathan
attached mail follows:
Jim Lucas wrote:
> Stut wrote:
>> Nathan Nobbe wrote:
>>> On Jan 30, 2008 11:31 AM, Stut <stuttle
gmail.com
>>> <mailto:stuttle
gmail.com>> wrote:
>>>
>>>
>>> "I would *just* use a static method"
>>>
>>> *just* *just* *just* *just* *just* *just* *just* *just* *just*
>>>
>>> No instance. None. Grrr.
>>>
>>>
>>> here is a mod of the code you posted w/ a var_dump() of the
>>> local variable $o;
>>>
>>> <?php
>>> class Test {
>>> public static function doSomething() {
>>> $o = new Test();
>>> var_dump($o);
>>> $o->_doSomething();
>>> }
>>>
>>> protected function _doSomething() {
>>> // I'm assuming this method is fairly complex, and involves
>>> // more than just this method, otherwise there is no point
>>> // in creating an instance of the class, just use a static
>>> // method.
>>> }
>>> }
>>> Test::doSomething();
>>> ?>
>>>
>>> nathan
gentooss ~/ticketsDbCode $ php testCode.php
>>> object(Test)#1 (0) {
>>> }
>>>
>>>
>>> clearly in the act of *just* using a static method, you *just*
>>> created an instance of class Test ;)
>>
>> Ok, I'm going to have to assume you really are as stupid as you seem.
>> If I need to provide an example to demonstrate what I meant I will,
>> but I feel I made it quite clear that my comment regarding what *I*
>> would do did not in any way relate to the code example I had provided
>> above. The example I provided was fulfilling the OP's requirements.
>>
>> This is what *I* would do...
>>
>> <?php
>> class Test {
>> public static function doSomething() {
>> // I'm assuming this method is fairly complex, and involves
>> // more than just this method, otherwise there is no point
>> // in creating an instance of the class, just use a static
>> // method.
>>
>> // ^^^^ See this comment here, this was taken from the
>> // non-static method in the example I posted. This is what
>> // I meant when I say "just use a static method".
>> }
>> }
>> Test::doSomething();
>> ?>
>>
>> Look ma, no instance.
>
> Now this is clear.
Glad to hear it.
> But to point out in the code I quoted, you said that you were going to
> only use the static method, but you were calling the static method that
> created an instance of the Test class and then calling the non-static
> method from the instance of the Test class.
I thought the comment in that static method explained that I didn't see
the point in creating the instance. I thought it was pretty clear, but
clearly not.
> Your previous example was not showing us what you were saying. To me it
> looked like you were confused about how you were calling/creating things.
I was never confused! ;)
-Stut
--
http://stut.net/
attached mail follows:
Nathan Nobbe wrote:
> On Jan 30, 2008 11:58 AM, Stut <stuttle
gmail.com
> <mailto:stuttle
gmail.com>> wrote:
>
> Ok, I'm going to have to assume you really are as stupid as you seem. If
> I need to provide an example to demonstrate what I meant I will, but I
> feel I made it quite clear that my comment regarding what *I* would do
> did not in any way relate to the code example I had provided above. The
> example I provided was fulfilling the OP's requirements.
>
> This is what *I* would do...
>
> <?php
> class Test {
> public static function doSomething() {
> // I'm assuming this method is fairly complex, and involves
> // more than just this method, otherwise there is no point
> // in creating an instance of the class, just use a static
> // method.
>
> // ^^^^ See this comment here, this was taken from the
> // non-static method in the example I posted. This is what
> // I meant when I say "just use a static method".
> }
> }
> Test::doSomething();
> ?>
>
> Look ma, no instance.
>
>
> well, at least its clear now, what you meant.
>
>
> FYI I'm not at all new to OOP, in general or in PHP, so I am well aware
> that the example I originally posted created an instance of the class.
>
>
> glad to hear it; no hard feelings i hope..
Indeed. Now, the place where you sleep... is it guarded?
;)
-Stut
--
http://stut.net/
attached mail follows:
>
> Indeed. Now, the place where you sleep... is it guarded?
well it is, but..
i probly misunderstood some implication in the directions of
my virtual fortress and therefore, probly not as well a i suspect ;)
-nathan
attached mail follows:
Janet N schreef:
> Hi there,
>
> I have two forms on the same php page. Both forms has php embeded inside
> html with it's own submit button.
>
> How do I keep the second form from not disappearing when I click submit on
> the first form? My issue is that when I click the submit button from the
> first
> form (register), the second form (signkey) disappear. Code below, any
> feedback is appreciated:
we the users clicks submit the form is submitted and a new page is returned. nothing
you can do about that (unless you go the AJAX route, but my guess is that's a little
out of your league given your question).
why not just use a single form that they can fill in, nothing in the logic
seems to require that they are seperate forms.
BTW your not validating or cleaning your request data. what happens when I submit
$_POST['domain'] with the following value?
'mydomain.com ; cd / ; rm -rf'
PS - I wouldn't try that $_POST['domain'] value.
PPS - font tags are so 1995
>
>
> <form name="register" method="post" action="/DKIMKey.php">
> <input type="submit" name="register" value="Submit Key">
>
> <?php
> if (isset($_POST['register']))
> {
> $register = $_POST['register'];
> }
> if (isset($register))
> {
> $filename = '/usr/local/register.sh';
> if(file_exists($filename))
> {
> $command = "/usr/local/register.sh ";
> $shell_lic = shell_exec($command);
> echo "<font size=2 color=blue>$shell_lic</font>";
> }
> }
> ?>
> </form>
>
>
>
> <form name="signkey" action="/DKIMKey.php" method="post"> <label
> domain="label">Enter the domain name: </label>
> <input name="domain" type="text"> <input type="submit" name="makesignkey"
> value="Submit"
>
> <?php
> if (isset($_POST['makesignkey']))
> {
> $makesignkey = $_POST['makesignkey'];
> }
> if (isset($makesignkey))
> {
> if(isset($_POST['domain']))
> {
> $filename = '/usr/local//keys/generatekeys';
> if(file_exists($filename))
> {
> $domain = $_POST['domain'];
> $command = "/usr/local/keys/generatekeys " . $domain;
>
> $shell_createDK = shell_exec($command);
> print("<p><font size=2
> color=blue>$shell_createDK</font></p>");
> }
> }
> ?>
> </form>
>
attached mail follows:
Nathan Nobbe wrote:
> all,
>
> i was playing around w/ some object serialization tonight during
> further exploration of spl and i stumbled on what appears to be a
> bug in the behavior of the __sleep() magic method.
>
> here is the pertinent documentation on the method
> ..is supposed to return an array with the names of all variables
> of that object that should be serialized.
>
> so, the idea is, *only* the instance variables identified in the array
> returned are marked for serialization.
> however, it appears all instance variables are being serialized no matter what.
> see the reproducible code below. ive run this on 2 separate php5
> boxes, one w/ 5.2.5, another w/ a 5.2.something..
>
> <?php
> class A {
> public $a1 = 'a1';
> public $a2 = 'a2';
> public $a3 = 'a3';
>
> public function __sleep() {
> echo __FUNCTION__ . PHP_EOL;
> return array('a1', 'a2');
> }
> }
>
> var_dump(unserialize(serialize(new A())));
> ?>
>
> this is what i get despite having marked only member variables 'a',
> and 'b' for serialization.
>
> __sleep
> object(A)#1 (3) {
> ["a1"]=>
> string(2) "a1"
> ["a2"]=>
> string(2) "a2"
> ["a3"]=>
> string(2) "a3"
> }
>
> consensus ?
>
To check if __sleep is proper, you should be doing
var_dump(serialize(new A()));
unserialize'ing effectively also does a __wakeup()
This should give a clearer picture
<?php
class A {
public $a1 = 'a1';
public $a2 = 'a2';
public $a3 = null;
public function __construct(){
$this->a3 = 'a3';
}
public function __sleep() {
echo __FUNCTION__ . PHP_EOL;
return array('a1', 'a2');
}
}
var_dump(unserialize(serialize(new A())));
?>
__sleep
object(A)#1 (3) {
["a1"]=>
string(2) "a1"
["a2"]=>
string(2) "a2"
["a3"]=>
NULL
}
============= and ======================
<?php
class A {
public $a1 = 'a1';
public $a2 = 'a2';
public $a3 = null;
public function __construct(){
$this->a3 = 'a3';
}
public function __sleep() {
echo __FUNCTION__ . PHP_EOL;
return array('a1', 'a2', 'a3');
}
}
var_dump(unserialize(serialize(new A())));
?>
__sleep
object(A)#1 (3) {
["a1"]=>
string(2) "a1"
["a2"]=>
string(2) "a2"
["a3"]=>
string(2) "a3"
}
--
Regards,
Anup Shukla
attached mail follows:
On Jan 29, 2008, at 4:29 PM, Nathan Nobbe wrote:
> On Jan 29, 2008 3:53 PM, Jason Pruim <japruim
raoset.com> wrote:
> I did as you suggested, and I think I found the reason... I included
> info for the doctype, and some files that are on all my pages...
> Once I comment out those lines it works just fine...
>
> I'm assuming that that is expected behavior?
>
> where did you include this information?
> i didnt see it in the original code you posted.
> and, btw. im no expert on setting mime types for excel :)
>
> -nathan
>
They were included in a config file I am working on... the
defaults.php file that has other config info, such as DB auth info and
system wide variables.
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim
raoset.com
attached mail follows:
On Jan 29, 2008 3:29 PM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> On Jan 29, 2008 3:19 PM, nihilism machine <nihilismmachine
gmail.com> wrote:
>
> > Ok, trying to write my first php5 class. This is my first project
> > using all OOP PHP5.2.5.
> >
> > I want to create a config class, which is extended by a connection
> > class, which is extended by a database class. Here is my config class,
> > how am I looking?
> >
> > <?php
> >
> > class dbconfig {
> > public $connInfo = array();
> > public $connInfo[$hostname] = 'internal-db.s23499.gridserver.com';
> > public $connInfo[$username] = 'db23499';
> > public $connInfo[$password] = 'ryvx4398';
> > public $connInfo[$database] = 'db23499_donors';
> >
> > public __construct() {
> > return $this->$connInfo;
> > }
> > }
> >
> > ?> <http://www.php.net/unsub.php>
>
>
> if youre going to have a class for configuration information; you probly
> should
> go for singleton:
> http://www.phppatterns.com/docs/design/singleton_pattern?s=singleton
>
> -nathan
>
Still pimping singleton, huh? :)
attached mail follows:
On Jan 30, 2008 8:40 AM, Eric Butera <eric.butera
gmail.com> wrote:
> On Jan 29, 2008 3:29 PM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> Still pimping singleton, huh? :)
>
hell yeah :)
i looked at the registry classes you pointed out.
you know what funny about the one in solar?
they refer to the same article i mentioned, namely,
the article at the phppatterns site. good to know
somebody else out there thinks highly of that site :)
also, i took a look (briefly though), in patterns of
enterprise architecture by martin fowler, which is
(perhaps) where the pattern was originally formalized.
he says that he prefers to have the data in the registry
stored in instance variables, but obviously there are ways
to vary the implementation of a pattern. ergo, in his
design the registry class itself would be a singleton.
it looks like the 3 examples you showed previously, are
all of essentially the same design. a class uses static
class members to store the data, and it is essentially
global, because well, any bit of code can reference the class.
id say the technique only works as a consequence of phps
dynamic nature, that is, in other languages like java and c++
i dont think you can create static class members on the fly.
the technique is certainly interesting.
-nathan
attached mail follows:
On Jan 30, 2008 9:57 AM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> On Jan 30, 2008 8:40 AM, Eric Butera <eric.butera
gmail.com> wrote:
>
> >
> >
> > On Jan 29, 2008 3:29 PM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> > Still pimping singleton, huh? :)
> >
>
> hell yeah :)
>
> i looked at the registry classes you pointed out.
> you know what funny about the one in solar?
> they refer to the same article i mentioned, namely,
> the article at the phppatterns site. good to know
> somebody else out there thinks highly of that site :)
>
> also, i took a look (briefly though), in patterns of
> enterprise architecture by martin fowler, which is
> (perhaps) where the pattern was originally formalized.
> he says that he prefers to have the data in the registry
> stored in instance variables, but obviously there are ways
> to vary the implementation of a pattern. ergo, in his
> design the registry class itself would be a singleton.
>
> it looks like the 3 examples you showed previously, are
> all of essentially the same design. a class uses static
> class members to store the data, and it is essentially
> global, because well, any bit of code can reference the class.
> id say the technique only works as a consequence of phps
> dynamic nature, that is, in other languages like java and c++
> i dont think you can create static class members on the fly.
> the technique is certainly interesting.
>
> -nathan
>
The only gripe I have about the registry pattern is the lack of code
completion in PDT. ;)
I love php patterns, but it seems to sort of be dead for years now.
I just keep downloading copies of various frameworks and poke through
their implementations. At the end of the day though it is my job to
write code, so I'm going to always balance the code purity vs getting
it done. I am okay with a registry that uses static methods because
it works in my projects. Some people would insist on being able to
create an instance and pass that around, but I don't need that level
of complexity.
attached mail follows:
On Jan 30, 2008 10:35 AM, Eric Butera <eric.butera
gmail.com> wrote:
> The only gripe I have about the registry pattern is the lack of code
> completion in PDT. ;)
heh. does that still blowup when you try to open a file w/ an interface
definition?
> I love php patterns, but it seems to sort of be dead for years now.
me too; ya, it is sort of dead, sad, but its still worth a look to people
getting
there feet wet w/ patterns, and occasionally as a point of reference for
patterns implemented in php.
> I just keep downloading copies of various frameworks and poke through
> their implementations.
this is a great idea, and youve got me doing more of it.
> At the end of the day though it is my job to
> write code, so I'm going to always balance the code purity vs getting
> it done. I am okay with a registry that uses static methods because
> it works in my projects.
its sorta like the 'php way' for the registry. theres something we can say
the java guys cant do ;)
Some people would insist on being able to
> create an instance and pass that around, but I don't need that level
> of complexity.
i dont think Registry::getInstance() is really that much overhead; but it is
another line of code to write :)
-nathan
attached mail follows:
On Jan 30, 2008 10:13 AM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> > I love php patterns, but it seems to sort of be dead for years now.
>
> me too; ya, it is sort of dead, sad, but its still worth a look to people
> getting
> there feet wet w/ patterns, and occasionally as a point of reference for
> patterns implemented in php.
If list traffic is any sign, PHP is indeed slowing down from the "new
peeps wanting to learn it" perspective:
http://marc.info/?l=php-general&w=2
I would assume it's because there are much more interesting advances
in web development technology to focus on elsewhere.
--
Greg Donald
http://destiney.com/
attached mail follows:
On Jan 30, 2008 11:38 AM, Greg Donald <gdonald
gmail.com> wrote:
> If list traffic is any sign, PHP is indeed slowing down from the "new
> peeps wanting to learn it" perspective:
>
> http://marc.info/?l=php-general&w=2
interesting..
<http://marc.info/?l=php-general&w=2>I would assume it's because there are
> much more interesting advances
> in web development technology to focus on elsewhere.
such as ?
-nathan
attached mail follows:
On Jan 30, 2008 11:13 AM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> i dont think Registry::getInstance() is really that much overhead;
In my initial tests I found that static methods accessing $GLOBALS
directly was much faster than using an instance and working on it
tucked away in a static variable. The getInstance() to pull and check
against the existence of the instance and creating it really added a
lot of extra code execution.
I use the intercept filter pattern on my code execution so that I can
set up different filters for authentication, authorization, gzip
output buffering, session management, etc based on my page needs. I
then wrap that around a front controller. So the registry has been
key in being able to push and pull data from many different scopes.
Then again sometimes I just use include files like the php patterns
site recommended[1].
Up until the start of this year my company was stuck in PHP4 since in
the real world clients don't want their sites to break because people
want the latest and greatest. :) A big reason I've had to dig around
is because I want to use the best ideas yet be able to run them on 4.
Now that we have 5 running everywhere it might be an option to
re-visit and use a fluent interface to do something like:
registry::getInstance()->get('foo');
I'd store the getInstance() instance in some sort of protected self::
accessed property and return if it exists or not. Maybe when I get
some free time I'll do a benchmark to see how nasty that is versus
just using static methods.
PDT hasn't ever crashed on me, but now that I've typed that... ;D
[1] http://www.phppatterns.com/docs/design/the_front_controller_and_php
attached mail follows:
On Jan 30, 2008 11:43 AM, Nathan Nobbe <quickshiftin
gmail.com> wrote:
> On Jan 30, 2008 11:38 AM, Greg Donald <gdonald
gmail.com> wrote:
>
> > If list traffic is any sign, PHP is indeed slowing down from the "new
> > peeps wanting to learn it" perspective:
> >
> > http://marc.info/?l=php-general&w=2
>
>
> interesting..
>
> <http://marc.info/?l=php-general&w=2>I would assume it's because there are
> > much more interesting advances
> > in web development technology to focus on elsewhere.
>