[PHP] Re: Casting objects.

2010-01-19 Thread Richard Quadling
2010/1/18 Shawn McKenzie :
> Shawn McKenzie wrote:
>>>
>> Never mind, that was stupid. I saw that somewhere before, but obviously
>> it doesn't work.
>>
>
> I found some code, maybe I redeem myself?
>
> static public function cast(&$object, $class=__CLASS__){
>
>        if(class_exists($class)) {
>                $object = unserialize(
>                        preg_replace('/^O:[0-9]+:"[^"]+":/i',
>                        'O:'.strlen($class).':"'.$class.'":',
>                        serialize($object)));
>        }
> }
>
> $row = odbc_fetch_object($result);
> structuresRemovalReason::cast($row);
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
That's an interesting approach.

Though I'm going to use reflection. I realise I need to hold some of
the data in strings where the data is not a string (datetimes for
example).

So, using a docblock with a customtag and this seems to be working just fine.

Extended ReflectionClass and ReflectionProperty.

Thanks,

Richard.


-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] Cookies & sessions

2010-01-19 Thread clancy_1
I am trying for the first time to use cookies. The manual contains the 
statement "Cookies
are part of the HTTP header, so setcookie() must be called before any output is 
sent to
the browser." 

When I first started using sessions, I was alarmed to read a very similar 
statement about
sessions, but I soon found that if I started my program with the statement
"session_start();" I could then set up, access, modify or clear any session 
variable at
any time in my program. This is enormously useful, as I can put the session 
handling at
any convenient point in my program, and can precede them with diagnostics if I 
need to.

However I have almost immediately found that while I appear to be able to read 
cookies at
any time, I cannot set them when I would like to. Is there any similar trick 
which will
work with cookies? If I really have to work out what they should be, and then 
set them up,
before issuing any diagnostics, etc, it will make life decidely more 
complicated. (I
assume that I can set several cookies using successive calls to setcookie()?)

I was also somewhat surprised to find that a cookie is used to implement 
sessions. Does
this place any limitations on using both sessions and cookies in the same 
program?


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



Re: [PHP] Cookies & sessions

2010-01-19 Thread Bruno Fajardo
2010/1/19  :
> I am trying for the first time to use cookies. The manual contains the 
> statement "Cookies
> are part of the HTTP header, so setcookie() must be called before any output 
> is sent to
> the browser."
>
> When I first started using sessions, I was alarmed to read a very similar 
> statement about
> sessions, but I soon found that if I started my program with the statement
> "session_start();" I could then set up, access, modify or clear any session 
> variable at
> any time in my program. This is enormously useful, as I can put the session 
> handling at
> any convenient point in my program, and can precede them with diagnostics if 
> I need to.
>
> However I have almost immediately found that while I appear to be able to 
> read cookies at
> any time, I cannot set them when I would like to. Is there any similar trick 
> which will
> work with cookies?

The only trick is that you have to call setcookie() before any output
is sent to the browser, just like the session_start() behavior.

> If I really have to work out what they should be, and then set them up,
> before issuing any diagnostics, etc, it will make life decidely more 
> complicated. (I
> assume that I can set several cookies using successive calls to setcookie()?)

Yes, each one with a differente name.

>
> I was also somewhat surprised to find that a cookie is used to implement 
> sessions. Does
> this place any limitations on using both sessions and cookies in the same 
> program?
>

No. The cookie in PHP that implements session is by default called
PHPSESSID. As long as your other cookies are named differently, you
should be fine.

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

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



Re: [PHP] Cookies & sessions

2010-01-19 Thread kranthi
> When I first started using sessions, I was alarmed to read a very similar 
> statement about
> sessions, but I soon found that if I started my program with the statement
> "session_start();" I could then set up, access, modify or clear any session 
> variable at
> any time in my program. This is enormously useful, as I can put the session 
> handling at
> any convenient point in my program, and can precede them with diagnostics if 
> I need to.

are you looking for ob_* functions ?

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



Re: [PHP] Cookies & sessions

2010-01-19 Thread Richard
Hi,

> However I have almost immediately found that while I appear to be able to 
> read cookies at
> any time, I cannot set them when I would like to. Is there any similar trick 
> which will
> work with cookies?

Keep in mind that cookies are set by sending an HTTP header as part of
the response, so until you do that they can't be sent back to you by
the client (and subsequently appear in $_COOKIE).

> (I assume that I can set several cookies using successive calls to 
> setcookie()?)

Sure. Not that I've done it.

> I was also somewhat surprised to find that a cookie is used to implement 
> sessions. Does
> this place any limitations on using both sessions and cookies in the same 
> program?

No (give them a different name though). You can also use sessions by
putting the session ID on the URL, but this, I believe, is called "a
ball ache".

-- 
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 16th January)
Follow me on Twitter: http://twitter.com/_rgraph
Lots of PHP and Javascript code - http://www.phpguru.org

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



Re: [PHP] 64 bit date in 32 bit php ??

2010-01-19 Thread Ashley Sheridan
On Mon, 2010-01-18 at 22:46 -0800, Michael A. Peters wrote:

> php 5.2.12 running in CentOS 5.x
> 
> Unfortunately, both my server (xen linode) and my test server (crappy 
> old dell I found in a field) are 32-bit. I need to work with some dates 
> earlier than 1901 and I would really prefer to store them in *nix time 
> in the database and use the date() function to format them for display 
> when I need to.
> 
> My understanding is that 32 bit php has a lower limit in 1901 and upper 
> limit in 2038 for the date function.
> 
> Is there a pcre / pecl / other wrapper that behaves identical to the 
> date function but uses a 64 bit float in 32 bit php?
> 
> Yes, the right thing to do is probably to use 64 bit, and if I could I 
> would. A wrapper that just passes it off to date on 64 bit systems and 
> to date on 32 bit systems within what data can handle and only does its 
> magic on 32 bit systems with values beyond 32-bit date capabilities 
> would be sweet.
> 


I've not used it, but the Pear Date class looks like it should do what
you need. I've used other Pear classes before, and they are pretty easy
to get to grips with, so I assume it should be the same for this one
too.

http://pear.php.net/package/Date

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] 64 Bit IIS 6 ( 32 Bit mode ) + 32Bit php connect with MS-SQL Server

2010-01-19 Thread Richard Quadling
2010/1/19  :
> 引述 Richard Quadling :
>
>> 1 - Can you confirm that the ini file you are editing is the one that
>> is reported in phpinfo() as the file being used?
>
> Yes, BUT there is no MSSQL info of it...
>
>> 2 - At a command prompt, change directory to your PHP installation  and
>> type ...
>>
>> php -m
>>
>> See if you have any errors being reported.
>>
>> If the INI file is in an unusual location, then use ...
>>
>> php -c  -m
>
> T:\php5>php -c t:\php5\php.ini -m
> PHP Warning:  PHP Startup: Unable to load dynamic library
> 'T:\PHP5\ext\php_mssql
> .dll' - The specified module could not be found.
>  in Unknown on line 0
> [PHP Modules]
> bcmath
> calendar
> com_dotnet
> ctype
> date
> dom
> filter
> ftp
> gd
> hash
> iconv
> json
> libxml
> mbstring
> mcrypt
> mysql
> odbc
> pcre
> Reflection
> session
> SimpleXML
> SPL
> standard
> tokenizer
> wddx
> xml
> xmlreader
> xmlwriter
> zlib
>
> [Zend Modules]
>
> T:\php5\ext>dir php_mssql.dll
>  Volume in drive T is Data
>  Volume Serial Number is DC85-706F
>
>  Directory of T:\php5\ext
>
> 2009/12/16  下午 05:06            49,232 php_mssql.dll
>               1 File(s)         49,232 bytes
>               0 Dir(s)  52,215,365,632 bytes free
>
> T:\php5\ext>
>
> BTW : when running the cli of php -c t:\php5\php.ini -m, the system prompt
> me there is no "MSVCR71.dll" found...
> So, how can I install the dll file for test ( php -m ) again ?
>
> Thanks !
>
> Edward.
>
>
>
>
>
> 
> ITA Web Site : http://www.ita.org.mo
> E-mail Address : i...@ita.org.mo
>
>

It seems you are missing one (or more) of the MS Visual C Runtime files.

http://www.microsoft.com/downloads/details.aspx?FamilyID=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
is where I'd go next.

But, first, I'd confirm this issue.

If you have depends.exe (http://www.dependencywalker.com/) to open the
php_mssql.dll and see if it reports the missing file in the same way -
look at the bottom of the bottom panel.

Whilst PHP _can_ find the php_mssql.dll file, it is unable to load it
due to missing libraries required by the dll.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] Cookies & sessions

2010-01-19 Thread Phpster

Be aware that there is a limit of 20 cookies per domain

Bastien

Sent from my iPod

On Jan 19, 2010, at 6:12 AM, Bruno Fajardo  wrote:


2010/1/19  :
I am trying for the first time to use cookies. The manual contains  
the statement "Cookies
are part of the HTTP header, so setcookie() must be called before  
any output is sent to

the browser."

When I first started using sessions, I was alarmed to read a very  
similar statement about
sessions, but I soon found that if I started my program with the  
statement
"session_start();" I could then set up, access, modify or clear any  
session variable at
any time in my program. This is enormously useful, as I can put the  
session handling at
any convenient point in my program, and can precede them with  
diagnostics if I need to.


However I have almost immediately found that while I appear to be  
able to read cookies at
any time, I cannot set them when I would like to. Is there any  
similar trick which will

work with cookies?


The only trick is that you have to call setcookie() before any output
is sent to the browser, just like the session_start() behavior.

If I really have to work out what they should be, and then set them  
up,
before issuing any diagnostics, etc, it will make life decidely  
more complicated. (I
assume that I can set several cookies using successive calls to  
setcookie()?)


Yes, each one with a differente name.



I was also somewhat surprised to find that a cookie is used to  
implement sessions. Does
this place any limitations on using both sessions and cookies in  
the same program?




No. The cookie in PHP that implements session is by default called
PHPSESSID. As long as your other cookies are named differently, you
should be fine.



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



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



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



Re: [PHP] 64 bit date in 32 bit php ??

2010-01-19 Thread Richard Quadling
2010/1/19 Ashley Sheridan :
> On Mon, 2010-01-18 at 22:46 -0800, Michael A. Peters wrote:
>
>> php 5.2.12 running in CentOS 5.x
>>
>> Unfortunately, both my server (xen linode) and my test server (crappy
>> old dell I found in a field) are 32-bit. I need to work with some dates
>> earlier than 1901 and I would really prefer to store them in *nix time
>> in the database and use the date() function to format them for display
>> when I need to.
>>
>> My understanding is that 32 bit php has a lower limit in 1901 and upper
>> limit in 2038 for the date function.
>>
>> Is there a pcre / pecl / other wrapper that behaves identical to the
>> date function but uses a 64 bit float in 32 bit php?
>>
>> Yes, the right thing to do is probably to use 64 bit, and if I could I
>> would. A wrapper that just passes it off to date on 64 bit systems and
>> to date on 32 bit systems within what data can handle and only does its
>> magic on 32 bit systems with values beyond 32-bit date capabilities
>> would be sweet.
>>
>
>
> I've not used it, but the Pear Date class looks like it should do what
> you need. I've used other Pear classes before, and they are pretty easy
> to get to grips with, so I assume it should be the same for this one
> too.
>
> http://pear.php.net/package/Date
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

php -r "$o = new DateTime('1066-10-14T14:30:00+'); echo $o->format('r');"

Battle of Hastings. Just after 2:30 on the 14th of October 1066.

As I understand things, the DateTime class avoids the 32bit issue entirely.

Take a listen to the excellent PHP|Architect Summer Web cast from last
year by Derick Rethans [1] & [2].

Regards,

Richard.

[1] http://phparch.com/webcasts
[2] http://mtadata.s3.amazonaws.com/webcasts/20090828-date-time.wmv
-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] 64 Bit IIS 6 ( 32 Bit mode ) + 32Bit php connect with MS-SQL Server

2010-01-19 Thread Edward S.P. Leong
Richard Quadling wrote:

>But having said all of that, the php_mssql.dll uses a very old library
>which may give you issues.
>
>For the time being, using ODBC (php_odbc is built in for PHP on
>Windows) is a much safer solution. You can also use the latest SQL
>Native Client driver so you can talk to SQL7, 2000, 2005, 2008.
>
>If you are used to using a DNS-less connection, then ...
>
>$Conn = odbc_pconnect("Driver={SQL Server Native Client
>10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
>$User, $Password, SQL_CUR_USE_DRIVER);
>
>will give you the connection without the need to have a DNS entry.
>  
>
Hello to you,

Where can we download the SQL Native Client driver for talking to MS-SQL
( eg : 2000 ) ?

Thanks !

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



Re: [PHP] 64 Bit IIS 6 ( 32 Bit mode ) + 32Bit php connect with MS-SQL Server

2010-01-19 Thread Richard Quadling
But having said all of that, the php_mssql.dll uses a very old library
which may give you issues.

For the time being, using ODBC (php_odbc is built in for PHP on
Windows) is a much safer solution. You can also use the latest SQL
Native Client driver so you can talk to SQL7, 2000, 2005, 2008.

If you are used to using a DNS-less connection, then ...

$Conn = odbc_pconnect("Driver={SQL Server Native Client
10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
$User, $Password, SQL_CUR_USE_DRIVER);

will give you the connection without the need to have a DNS entry.

-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



Re: [PHP] 64 Bit IIS 6 ( 32 Bit mode ) + 32Bit php connect with MS-SQL Server

2010-01-19 Thread Richard Quadling
2010/1/19 Edward S.P. Leong :
> Richard Quadling wrote:
>
>>But having said all of that, the php_mssql.dll uses a very old library
>>which may give you issues.
>>
>>For the time being, using ODBC (php_odbc is built in for PHP on
>>Windows) is a much safer solution. You can also use the latest SQL
>>Native Client driver so you can talk to SQL7, 2000, 2005, 2008.
>>
>>If you are used to using a DNS-less connection, then ...
>>
>>$Conn = odbc_pconnect("Driver={SQL Server Native Client
>>10.0};Server={$Server};Database={$Database};MARS_Connection=Yes;",
>>$User, $Password, SQL_CUR_USE_DRIVER);
>>
>>will give you the connection without the need to have a DNS entry.
>>
>>
> Hello to you,
>
> Where can we download the SQL Native Client driver for talking to MS-SQL
> ( eg : 2000 ) ?
>
> Thanks !
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C3E9EF-BA29-4A43-8D69-A2BED18FE73C&displaylang=en

and you also have the option of an official MS SQL driver for PHP

http://www.codeplex.com/SQLSRVPHP


-- 
-
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

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



[PHP] Object Oriented Programming question

2010-01-19 Thread Ben Stones
Hi,

I've been learning about object oriented programming for the past few weeks
and I've understood it pretty well, but I have one question. Usually with
PHP scripts I make, all the functionality for a specific page is in the
actual PHP file, and I'd use PHP functions in a separate directory which
would be included in whichever PHP file needs specific functions I have
created. The functions would be for the specific things in my script, such
as validation checks, functionality that will be used/repeated a lot
throughout my script, etc. What I don't understand about OOP is what its
primary purpose is for. Do I use OOP for all the functionality of my
application, in separate directories, and include these specific class files
and call the methods to complete specific functionality needed for whatever
PHP file I'm working on, or is OOP used for specific functionality like I
would with functions? Essentially what I'm asking is what is the primary
purpose for OOP? Hope you understand.

Thanks,


RE: [PHP] Object Oriented Programming question

2010-01-19 Thread Bob McConnell
From: Ben Stones

> I've been learning about object oriented programming for the past few
weeks
> and I've understood it pretty well, but I have one question. Usually
with
> PHP scripts I make, all the functionality for a specific page is in
the
> actual PHP file, and I'd use PHP functions in a separate directory
which
> would be included in whichever PHP file needs specific functions I
have
> created. The functions would be for the specific things in my script,
such
> as validation checks, functionality that will be used/repeated a lot
> throughout my script, etc. What I don't understand about OOP is what
its
> primary purpose is for. Do I use OOP for all the functionality of my
> application, in separate directories, and include these specific class
files
> and call the methods to complete specific functionality needed for
whatever
> PHP file I'm working on, or is OOP used for specific functionality
like I
> would with functions? Essentially what I'm asking is what is the
primary
> purpose for OOP? Hope you understand.

OOP is a way of looking at a problem and map it into code. Some problems
will fit into it, some don't. Some people can look at problems and see
objects and some can't. But in most cases, it is not easy to take an
existing procedural program and re-map it into objects. It would be
easier to start over from the specification and write it from scratch in
the object model.

If you have been doing procedural programming, don't worry if you don't
figure it out right away. It is not an easy transition to make. Many of
us with decades of programming behind us will never be able to make that
switch. Our brains are too tightly locked into the previous thought
patterns.

Bob McConnell

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



Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Floyd Resler
Ben,
I use a combination of procedural and OOP in my scripts.  It depends on 
my needs.  As an example, I use OOP for gathering order information.  I created 
a class which gathers all the order information allowing me to easily access 
any piece of data in the order.  I could do this with a bunch of individual 
functions but it's easier and more logical to group them all together in a 
single class.  When I first started working with classes, I used them 
sparingly.  Now I find myself using them more and more.

Take care,
Floyd

On Jan 19, 2010, at 10:11 AM, Ben Stones wrote:

> Hi,
> 
> I've been learning about object oriented programming for the past few weeks
> and I've understood it pretty well, but I have one question. Usually with
> PHP scripts I make, all the functionality for a specific page is in the
> actual PHP file, and I'd use PHP functions in a separate directory which
> would be included in whichever PHP file needs specific functions I have
> created. The functions would be for the specific things in my script, such
> as validation checks, functionality that will be used/repeated a lot
> throughout my script, etc. What I don't understand about OOP is what its
> primary purpose is for. Do I use OOP for all the functionality of my
> application, in separate directories, and include these specific class files
> and call the methods to complete specific functionality needed for whatever
> PHP file I'm working on, or is OOP used for specific functionality like I
> would with functions? Essentially what I'm asking is what is the primary
> purpose for OOP? Hope you understand.
> 
> Thanks,


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



Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Ashley Sheridan
On Tue, 2010-01-19 at 15:11 +, Ben Stones wrote:

> Hi,
> 
> I've been learning about object oriented programming for the past few weeks
> and I've understood it pretty well, but I have one question. Usually with
> PHP scripts I make, all the functionality for a specific page is in the
> actual PHP file, and I'd use PHP functions in a separate directory which
> would be included in whichever PHP file needs specific functions I have
> created. The functions would be for the specific things in my script, such
> as validation checks, functionality that will be used/repeated a lot
> throughout my script, etc. What I don't understand about OOP is what its
> primary purpose is for. Do I use OOP for all the functionality of my
> application, in separate directories, and include these specific class files
> and call the methods to complete specific functionality needed for whatever
> PHP file I'm working on, or is OOP used for specific functionality like I
> would with functions? Essentially what I'm asking is what is the primary
> purpose for OOP? Hope you understand.
> 
> Thanks,


There are a few advantages by going the OOP route with PHP.

Firstly, you can bring together what would normally be in several
variables into one object, making it easier to work with, instead of
having to use various global variables to hold all the information.
Also, you can instantiate more than one object of the same type, and it
is a lot easier to work with than global variables. For some complex
cases, you could only manage this with a huge global array, which would
become unwieldy if made too large.

Secondly, object allow inheritance. So, if you create an object class,
you could use that as a basis for another more complex object by
building upon it with inheritance. You can also use other classes as a
basis for a more complex one of your own. Pear does this quite a lot.

Lastly, with OOP, you can create functions that can only be called from
within your object. These methods allow you to create functions that
will only ever be used by your classes, and won't accidentally be called
from anywhere else in your scripts.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Paul M Foster
On Tue, Jan 19, 2010 at 03:11:56PM +, Ben Stones wrote:

> Hi,
> 
> I've been learning about object oriented programming for the past few weeks
> and I've understood it pretty well, but I have one question. Usually with
> PHP scripts I make, all the functionality for a specific page is in the
> actual PHP file, and I'd use PHP functions in a separate directory which
> would be included in whichever PHP file needs specific functions I have
> created. The functions would be for the specific things in my script, such
> as validation checks, functionality that will be used/repeated a lot
> throughout my script, etc. What I don't understand about OOP is what its
> primary purpose is for. Do I use OOP for all the functionality of my
> application, in separate directories, and include these specific class files
> and call the methods to complete specific functionality needed for whatever
> PHP file I'm working on, or is OOP used for specific functionality like I
> would with functions? Essentially what I'm asking is what is the primary
> purpose for OOP? Hope you understand.



OOP is a *trend* or *fad* in programming. You can create a whole
application written almost entirely with OOP. It will usually follow the
MVC (Model-View-Controller) paradigm. It will have a front controller
(one page that every other page starts from) and distribute the work of
displaying pages, validating values, and storing data across a variety
of classes in a bunch of files. See a package called CodeIgniter for a
good but simple example of this paradigm. Generally, an application
written this way will load many tens of pages' worth of code before any
byte gets to the screen.

Alternatively, you can write simple OOP components for selected parts of
your application. For example, if you're dealing with a bunch of
customer screens, you can write an object oriented class which handles
all the customer queries with the database.

There are a variety of arguments that OOP advocates will make in favor
of OOP. It's *supposed* to make your programming easier and faster, and
make for easier debugging. In the real world, this may or may not be
true. OOP does work to reduce the clutter in your namespaces-- the
names of methods within classes are hidden from the rest of your
namespace, unlike global functions. It also relieves you from having to
pass a lot of parameters to each routine you call; you can store a lot
of properties in the class, and they are shared with the methods in the
class.

One of the more serious problems I've seen with OOP lies with classes
which have dependencies on other classes. It's like walking a minefield
sometimes, ensuring that this class gets instantiated before that one,
which depends on it. You can write an incredibly complicated automatic
instantiator which instantiates classes and ensures they fire in the
proper order (I have), but it seems kind of silly when you could just as
easily write external functions which perform similar functions.



Bottom line is, study OOP (look it up in wikipedia.org), and if you
think its advantages are worth your effort to learn the new paradigm, go
with it. But ignore the hype (and there's a lot of it). Do what works
for you.



Paul

-- 
Paul M. Foster

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



Re: [PHP] Cookies & sessions

2010-01-19 Thread Paul M Foster
On Tue, Jan 19, 2010 at 10:06:26PM +1100, clanc...@cybec.com.au wrote:

> I am trying for the first time to use cookies. The manual contains the
> statement "Cookies
> are part of the HTTP header, so setcookie() must be called before any
> output is sent to
> the browser."
> 
> When I first started using sessions, I was alarmed to read a very similar
> statement about
> sessions, but I soon found that if I started my program with the statement
> "session_start();" I could then set up, access, modify or clear any session
> variable at
> any time in my program. This is enormously useful, as I can put the session
> handling at
> any convenient point in my program, and can precede them with diagnostics
> if I need to.
> 
> However I have almost immediately found that while I appear to be able to
> read cookies at
> any time, I cannot set them when I would like to. Is there any similar
> trick which will
> work with cookies? If I really have to work out what they should be,
> and then set them up,
> before issuing any diagnostics, etc, it will make life decidely more
> complicated. (I
> assume that I can set several cookies using successive calls to setcookie()?)

Session variables are available throughout your session. Cookie
variables are only available if you read them into variables you can
access. Changes to session variables will the flushed to the server when
your page is terminated. Cookie variables are flushed to disk if you
make the appropriate *_cookie() function call, and even then I don't
know if this is actually echoed to disk until your page is terminated.

> 
> I was also somewhat surprised to find that a cookie is used to implement
> sessions. Does
> this place any limitations on using both sessions and cookies in the
> same program?

I don't believe so. If I'm not mistaken, session values are stored on the
server, not on the client. What's stored on the client is the session
ID.

Please bear in mind my understanding of cookies is fragmentary, and I
hope someone else will write in to correct any incorrect statements I've
made.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Ashley Sheridan
On Tue, 2010-01-19 at 12:30 -0500, Paul M Foster wrote:

> On Tue, Jan 19, 2010 at 03:11:56PM +, Ben Stones wrote:
> 
> > Hi,
> > 
> > I've been learning about object oriented programming for the past few weeks
> > and I've understood it pretty well, but I have one question. Usually with
> > PHP scripts I make, all the functionality for a specific page is in the
> > actual PHP file, and I'd use PHP functions in a separate directory which
> > would be included in whichever PHP file needs specific functions I have
> > created. The functions would be for the specific things in my script, such
> > as validation checks, functionality that will be used/repeated a lot
> > throughout my script, etc. What I don't understand about OOP is what its
> > primary purpose is for. Do I use OOP for all the functionality of my
> > application, in separate directories, and include these specific class files
> > and call the methods to complete specific functionality needed for whatever
> > PHP file I'm working on, or is OOP used for specific functionality like I
> > would with functions? Essentially what I'm asking is what is the primary
> > purpose for OOP? Hope you understand.
> 
> 
> 
> OOP is a *trend* or *fad* in programming. You can create a whole
> application written almost entirely with OOP. It will usually follow the
> MVC (Model-View-Controller) paradigm. It will have a front controller
> (one page that every other page starts from) and distribute the work of
> displaying pages, validating values, and storing data across a variety
> of classes in a bunch of files. See a package called CodeIgniter for a
> good but simple example of this paradigm. Generally, an application
> written this way will load many tens of pages' worth of code before any
> byte gets to the screen.
> 
> Alternatively, you can write simple OOP components for selected parts of
> your application. For example, if you're dealing with a bunch of
> customer screens, you can write an object oriented class which handles
> all the customer queries with the database.
> 
> There are a variety of arguments that OOP advocates will make in favor
> of OOP. It's *supposed* to make your programming easier and faster, and
> make for easier debugging. In the real world, this may or may not be
> true. OOP does work to reduce the clutter in your namespaces-- the
> names of methods within classes are hidden from the rest of your
> namespace, unlike global functions. It also relieves you from having to
> pass a lot of parameters to each routine you call; you can store a lot
> of properties in the class, and they are shared with the methods in the
> class.
> 
> One of the more serious problems I've seen with OOP lies with classes
> which have dependencies on other classes. It's like walking a minefield
> sometimes, ensuring that this class gets instantiated before that one,
> which depends on it. You can write an incredibly complicated automatic
> instantiator which instantiates classes and ensures they fire in the
> proper order (I have), but it seems kind of silly when you could just as
> easily write external functions which perform similar functions.
> 
> 
> 
> Bottom line is, study OOP (look it up in wikipedia.org), and if you
> think its advantages are worth your effort to learn the new paradigm, go
> with it. But ignore the hype (and there's a lot of it). Do what works
> for you.
> 
> 
> 
> Paul
> 
> -- 
> Paul M. Foster
> 


I wouldn't call OOP a fad really, as that suggest a silly short-term
trend, but you do bring up a good point about class dependency problems.
If dependencies are causing that sort of level of problem, then it might
be worth re-making part of the wheel (after all, you wouldn't see wooden
cart wheels on a Ferrari, would you?!)

I've seen plenty of sites use no OOP at all, but I think once a system
gets beyond a certain size, it does make more sense to use OOP, just to
avoid running into problems where you have so many functions performing
so many tasks but becoming a nightmare to maintain.

Oh, and your flame suit failed because you forgot the quotation marks
around the attribute values, and you didn't close the tag :p

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Paul M Foster
On Tue, Jan 19, 2010 at 05:44:56PM +, Ashley Sheridan wrote:



> 
> Oh, and your flame suit failed because you forgot the quotation marks around
> the attribute values, and you didn't close the tag :p

Dang! I *thought* it felt awfully warm in here.

Paul

-- 
Paul M. Foster

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



Re: [PHP] Cookies & sessions

2010-01-19 Thread Adam Richardson
On Tue, Jan 19, 2010 at 12:42 PM, Paul M Foster wrote:

> On Tue, Jan 19, 2010 at 10:06:26PM +1100, clanc...@cybec.com.au wrote:
>
> > I am trying for the first time to use cookies. The manual contains the
> > statement "Cookies
> > are part of the HTTP header, so setcookie() must be called before any
> > output is sent to
> > the browser."
> >
> > When I first started using sessions, I was alarmed to read a very similar
> > statement about
> > sessions, but I soon found that if I started my program with the
> statement
> > "session_start();" I could then set up, access, modify or clear any
> session
> > variable at
> > any time in my program. This is enormously useful, as I can put the
> session
> > handling at
> > any convenient point in my program, and can precede them with diagnostics
> > if I need to.
> >
> > However I have almost immediately found that while I appear to be able to
> > read cookies at
> > any time, I cannot set them when I would like to. Is there any similar
> > trick which will
> > work with cookies? If I really have to work out what they should be,
> > and then set them up,
> > before issuing any diagnostics, etc, it will make life decidely more
> > complicated. (I
> > assume that I can set several cookies using successive calls to
> setcookie()?)
>
> Session variables are available throughout your session. Cookie
> variables are only available if you read them into variables you can
> access. Changes to session variables will the flushed to the server when
> your page is terminated. Cookie variables are flushed to disk if you
> make the appropriate *_cookie() function call, and even then I don't
> know if this is actually echoed to disk until your page is terminated.
>
> >
> > I was also somewhat surprised to find that a cookie is used to implement
> > sessions. Does
> > this place any limitations on using both sessions and cookies in the
> > same program?
>
> I don't believe so. If I'm not mistaken, session values are stored on the
> server, not on the client. What's stored on the client is the session
> ID.
>
> Please bear in mind my understanding of cookies is fragmentary, and I
> hope someone else will write in to correct any incorrect statements I've
> made.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

>

> I was also somewhat surprised to find that a cookie is used to implement

> sessions. Does

> this place any limitations on using both sessions and cookies in the

> same program?


There shouldn't be any issue.  By default, PHP uses a cookie named
PHPSESSIONID to associate a particular visitor with their corresponding
session data stored server-side.  So, just be sure not to use a cookie
called "PHPSESSIONID".


-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com


Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Robert Cummings

Ashley Sheridan wrote:

On Tue, 2010-01-19 at 12:30 -0500, Paul M Foster wrote:


On Tue, Jan 19, 2010 at 03:11:56PM +, Ben Stones wrote:


Hi,

I've been learning about object oriented programming for the past few weeks
and I've understood it pretty well, but I have one question. Usually with
PHP scripts I make, all the functionality for a specific page is in the
actual PHP file, and I'd use PHP functions in a separate directory which
would be included in whichever PHP file needs specific functions I have
created. The functions would be for the specific things in my script, such
as validation checks, functionality that will be used/repeated a lot
throughout my script, etc. What I don't understand about OOP is what its
primary purpose is for. Do I use OOP for all the functionality of my
application, in separate directories, and include these specific class files
and call the methods to complete specific functionality needed for whatever
PHP file I'm working on, or is OOP used for specific functionality like I
would with functions? Essentially what I'm asking is what is the primary
purpose for OOP? Hope you understand.



OOP is a *trend* or *fad* in programming. You can create a whole
application written almost entirely with OOP. It will usually follow the
MVC (Model-View-Controller) paradigm. It will have a front controller
(one page that every other page starts from) and distribute the work of
displaying pages, validating values, and storing data across a variety
of classes in a bunch of files. See a package called CodeIgniter for a
good but simple example of this paradigm. Generally, an application
written this way will load many tens of pages' worth of code before any
byte gets to the screen.

Alternatively, you can write simple OOP components for selected parts of
your application. For example, if you're dealing with a bunch of
customer screens, you can write an object oriented class which handles
all the customer queries with the database.

There are a variety of arguments that OOP advocates will make in favor
of OOP. It's *supposed* to make your programming easier and faster, and
make for easier debugging. In the real world, this may or may not be
true. OOP does work to reduce the clutter in your namespaces-- the
names of methods within classes are hidden from the rest of your
namespace, unlike global functions. It also relieves you from having to
pass a lot of parameters to each routine you call; you can store a lot
of properties in the class, and they are shared with the methods in the
class.

One of the more serious problems I've seen with OOP lies with classes
which have dependencies on other classes. It's like walking a minefield
sometimes, ensuring that this class gets instantiated before that one,
which depends on it. You can write an incredibly complicated automatic
instantiator which instantiates classes and ensures they fire in the
proper order (I have), but it seems kind of silly when you could just as
easily write external functions which perform similar functions.



Bottom line is, study OOP (look it up in wikipedia.org), and if you
think its advantages are worth your effort to learn the new paradigm, go
with it. But ignore the hype (and there's a lot of it). Do what works
for you.



Paul

--
Paul M. Foster




I wouldn't call OOP a fad really, as that suggest a silly short-term
trend, but you do bring up a good point about class dependency problems.
If dependencies are causing that sort of level of problem, then it might
be worth re-making part of the wheel (after all, you wouldn't see wooden
cart wheels on a Ferrari, would you?!)

I've seen plenty of sites use no OOP at all, but I think once a system
gets beyond a certain size, it does make more sense to use OOP, just to
avoid running into problems where you have so many functions performing
so many tasks but becoming a nightmare to maintain.


I would have to agree that OOP is not a fad, perhaps over-hyped at 
times, but definitely not a fad. The argument about class dependencies 
is an invalid argument since functions will also have dependencies on 
other functions from other libraries, quite likely located in multiple 
source files. In fact, you've argued an advantage for OOP in the context 
of PHP since autoload can be used to mitigate this issue for classes, 
but not for functions. Another advantage of OOP that is difficult to 
provide via the procedural paradigm is polymorphism.


Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

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



Re: [PHP] Zend debugger doesn't work

2010-01-19 Thread Jochem Maas
Op 1/18/10 10:38 AM, Ali Asghar Toraby Parizy schreef:
> Hi
> I have installed php 5.3.1 (with thread safety = on) recently And I

I would try without thread safety to start with, 'std' setup uses
the pre-fork model which doesn't need it and *may* cause probs. [fast]CGI
doesn't need thread safety either IIRC.

> tried to install zend debugger yesterday. I downloaded zend debugger
> extension from http://downloads.zend.com/pdt/server-debugger/
> But I didn't find dll module for 5.3.x release. So I tried dll file in
> 5_2_x_comp folder. When I start Apache, I have a line in log file that

that 5.2 version won't work.

> says:

I think you can DL a 5.3 compatible module from:

http://www.zend.com/en/products/studio/downloads

requires registration IIRC.

> Apache/2.2.14 (Win32) PHP/5.3.1 configured -- resuming normal operations
> And phpinfo() says nothing about debugger module! What do you think
> about this thing? I haven't seen any error, But there is no debug
> session!

if your not seeing any errors related to failing to load then you have
either not made the required changed to php.ini or the changes you made are
not at all correct (and php is ignoring them) ... I did also read stuff about 
the
zend_* php.ini directives no longer supporting the '_ts' variants in php5.3, but
I have on idea if that is correct.

> Should I wait for 5.3.x release of zend debugger?


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



Re: [PHP] Object Oriented Programming question

2010-01-19 Thread Paul M Foster
On Tue, Jan 19, 2010 at 01:12:49PM -0500, Robert Cummings wrote:



>
> I would have to agree that OOP is not a fad, perhaps over-hyped at
> times, but definitely not a fad. The argument about class dependencies
> is an invalid argument since functions will also have dependencies on
> other functions from other libraries, quite likely located in multiple
> source files. 

Yes, functions can have dependencies as well, but you simply call the
function you need from within another function. It's been done for
decades in C and any number of other languages. Anyone who's ever
programmed in C (or comparable language) is familiar with having to do
"includes" at the beginning of source files and simply calling functions
now visible or now linked. This practice is frowned upon in OOP, or
"dependency injection" wouldn't have been written about so much.

> In fact, you've argued an advantage for OOP in the context
> of PHP since autoload can be used to mitigate this issue for classes,
> but not for functions. 

Autoloading doesn't mitigate class interdependency unless you build an
autoload function which handles dependency injection transparently.
Again, a complex proposition.

> Another advantage of OOP that is difficult to
> provide via the procedural paradigm is polymorphism.

Agreed. Though the advantages of polymorphism are questionable,
depending on your viewpoint.

Paul

-- 
Paul M. Foster

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



[PHP] Iterating ASTs with SPL in PHP-5.3.1

2010-01-19 Thread Aspra Flavius Adrian
Hi

I have an abstract syntax tree which I need to iterate. The AST is generated
by the lemon port to PHP, found in PEAR.

Now "normally", I'd do it with the brand new and shiny (PHP 5.3.1) SPL
classes, and it would look like this:

$it = new \RecursiveIteratorIterator(
  new \RecursiveArrayIterator($ast),
  \RecursiveIteratorIterator::SELF_FIRST);

Actually, that's what I'm already doing in another part of the code which
determinates a rough type of the entire tree (i.e it can be an assignment, a
condition, etc). Now details aside, the only important thing is the
iteration is done in a RecursiveIteratorIterator::SELF_FIRST manner, that
is, top-down.

Going back to my problem, I need to iterate the AST bottom-up, that is,
something like RecursiveIteratorIterator::CHILD_FIRST, in order to do some
substitutions and optimizations in the tree.

The problem is, these operations need to be context-aware, i.e. I need the
path down to the current node, starting at the root. And since I want to
iterate bottom-up, I can't have that with RecursiveIteratorIterator, at
least not with it alone.

Well think about it for a second. I want to iterate bottom-up and have the
top-down context (a stack) of the current node, at each iteration.
Technically it should be possible, since RecursiveIteratorIterator must
first go to the tail of the tree(I assume), in order to iterate it
backwards. In its way to the tail, it could cache the current position, and
simply pop out elements as it returns back from recursion.

Now this is a keyword: **caching**. This is why I suspect it should be
possible with another SPL class: RecursiveCachingIterator.

The question is: is it really possible? If yes, how?

I've been trying to puzzle around with some code, without success, and the
documentation is scarce. Really, really scarce.

So I'm looking for **as much SPL (re)usage as possible**. I know I could
write my own recursive functions with a custom stack.

A small PoC would be welcome.

Thanks

--
Flavius Aspra


[PHP] Re: Casting objects.

2010-01-19 Thread Carlos Medina

Richard Quadling schrieb:

2010/1/18 Shawn McKenzie :

Shawn McKenzie wrote:

Never mind, that was stupid. I saw that somewhere before, but obviously
it doesn't work.


I found some code, maybe I redeem myself?

static public function cast(&$object, $class=__CLASS__){

   if(class_exists($class)) {
   $object = unserialize(
   preg_replace('/^O:[0-9]+:"[^"]+":/i',
   'O:'.strlen($class).':"'.$class.'":',
   serialize($object)));
   }
}

$row = odbc_fetch_object($result);
structuresRemovalReason::cast($row);

--
Thanks!
-Shawn
http://www.spidean.com


That's an interesting approach.

Though I'm going to use reflection. I realise I need to hold some of
the data in strings where the data is not a string (datetimes for
example).

So, using a docblock with a customtag and this seems to be working just fine.

Extended ReflectionClass and ReflectionProperty.

Thanks,

Richard.



Hi,
i think it will be important since more PHP Developer are using Design
Patterns. I think the cast functionality should be implemented once...

Regards

Carlos

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



RE: [PHP] order by ASC

2010-01-19 Thread Daevid Vincent
http://www.webdeveloper.com/forum/showthread.php?t=101174

You could do it like this too...

ORDER BY `rollnumber` + 0 ASC 

And if you just got the data out in mysql (no ORDER BY -- which can be slow
in mysql), you could use PHP's sort as well...

http://php.net/manual/en/function.natsort.php

> -Original Message-
> From: Robert Cummings [mailto:rob...@interjinn.com] 
> Sent: Saturday, January 16, 2010 9:37 PM
> To: John Taylor-Johnston
> Cc: PHP-General
> Subject: Re: [PHP] order by ASC
> 
> John Taylor-Johnston wrote:
> > Did some googling. This worked:
> > ORDER BY CAST(`rollnumber` AS SIGNED)
> > 
> > What is the difference? My problem in the meanwhile must be 
> my version 
> > of MySQL?
> 
> You could have skipped quotes altogether. The difference is 
> that you are 
> referencing a field name, not a string value.
> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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



RE: [PHP] order by ASC

2010-01-19 Thread Ashley Sheridan
On Tue, 2010-01-19 at 16:16 -0800, Daevid Vincent wrote:

> http://www.webdeveloper.com/forum/showthread.php?t=101174
> 
> You could do it like this too...
> 
> ORDER BY `rollnumber` + 0 ASC 
> 
> And if you just got the data out in mysql (no ORDER BY -- which can be slow
> in mysql), you could use PHP's sort as well...
> 
> http://php.net/manual/en/function.natsort.php
> 
> > -Original Message-
> > From: Robert Cummings [mailto:rob...@interjinn.com] 
> > Sent: Saturday, January 16, 2010 9:37 PM
> > To: John Taylor-Johnston
> > Cc: PHP-General
> > Subject: Re: [PHP] order by ASC
> > 
> > John Taylor-Johnston wrote:
> > > Did some googling. This worked:
> > > ORDER BY CAST(`rollnumber` AS SIGNED)
> > > 
> > > What is the difference? My problem in the meanwhile must be 
> > my version 
> > > of MySQL?
> > 
> > You could have skipped quotes altogether. The difference is 
> > that you are 
> > referencing a field name, not a string value.
> > 
> > Cheers,
> > Rob.
> > -- 
> > http://www.interjinn.com
> > Application and Templating Framework for PHP
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> > 
> 
> 


I've always found that ordering is much faster in MySQL than PHP. You
use quite a lot of memory sorting in PHP as well, as you first have to
load the whole result set into an array, which is additional to any
memory used in the result set by PHP and MySQL anyway.

Thanks,
Ash
http://www.ashleysheridan.co.uk




RE: [PHP] order by ASC

2010-01-19 Thread Daevid Vincent
http://lmgtfy.com/?q=mysql+order+by+slow
 
it's notoriously slow to use ORDER BY with large tables. Mainly b/c mySQL
has to use a hash/temp table to re-sort AFAIK.
 
I wasn't thinking of sorting the whole set, only the list of numbers as the
OP only talked about sorting a single column...
 
>>> rollnumber is a varchar(50). I need it to be a text field. ASC does 
>>> not order the way I want.
>>>
>>> 1000
>>> 1001
>>> 998
>>> 999
>>>
>>> I want it to order like this:
>>>
>>> 998
>>> 999
>>> 1000
>>> 1001


  _  

From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
Sent: Tuesday, January 19, 2010 4:40 PM
To: Daevid Vincent
Cc: 'PHP-General'
Subject: RE: [PHP] order by ASC


On Tue, 2010-01-19 at 16:16 -0800, Daevid Vincent wrote: 

http://www.webdeveloper.com/forum/showthread.php?t=101174



You could do it like this too...



ORDER BY `rollnumber` + 0 ASC 



And if you just got the data out in mysql (no ORDER BY -- which can be slow

in mysql), you could use PHP's sort as well...



http://php.net/manual/en/function.natsort.php



> -Original Message-

> From: Robert Cummings [mailto:rob...@interjinn.com] 

> Sent: Saturday, January 16, 2010 9:37 PM

> To: John Taylor-Johnston

> Cc: PHP-General

> Subject: Re: [PHP] order by ASC

> 

> John Taylor-Johnston wrote:

> > Did some googling. This worked:

> > ORDER BY CAST(`rollnumber` AS SIGNED)

> > 

> > What is the difference? My problem in the meanwhile must be 

> my version 

> > of MySQL?

> 

> You could have skipped quotes altogether. The difference is 

> that you are 

> referencing a field name, not a string value.

> 

> Cheers,

> Rob.

> -- 

> http://www.interjinn.com

> Application and Templating Framework for PHP

> 

> -- 

> PHP General Mailing List (http://www.php.net/)

> To unsubscribe, visit: http://www.php.net/unsub.php

> 






I've always found that ordering is much faster in MySQL than PHP. You use
quite a lot of memory sorting in PHP as well, as you first have to load the
whole result set into an array, which is additional to any memory used in
the result set by PHP and MySQL anyway.


Thanks,
Ash
http://www.ashleysheridan.co.uk






RE: [PHP] order by ASC

2010-01-19 Thread Ashley Sheridan
On Tue, 2010-01-19 at 17:11 -0800, Daevid Vincent wrote:

> http://lmgtfy.com/?q=mysql+order+by+slow
>  
> it's notoriously slow to use ORDER BY with large tables. Mainly b/c mySQL
> has to use a hash/temp table to re-sort AFAIK.
>  
> I wasn't thinking of sorting the whole set, only the list of numbers as the
> OP only talked about sorting a single column...
>  
> >>> rollnumber is a varchar(50). I need it to be a text field. ASC does 
> >>> not order the way I want.
> >>>
> >>> 1000
> >>> 1001
> >>> 998
> >>> 999
> >>>
> >>> I want it to order like this:
> >>>
> >>> 998
> >>> 999
> >>> 1000
> >>> 1001
> 
> 
>   _  
> 
> From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] 
> Sent: Tuesday, January 19, 2010 4:40 PM
> To: Daevid Vincent
> Cc: 'PHP-General'
> Subject: RE: [PHP] order by ASC
> 
> 
> On Tue, 2010-01-19 at 16:16 -0800, Daevid Vincent wrote: 
> 
> http://www.webdeveloper.com/forum/showthread.php?t=101174
> 
> 
> 
> You could do it like this too...
> 
> 
> 
> ORDER BY `rollnumber` + 0 ASC 
> 
> 
> 
> And if you just got the data out in mysql (no ORDER BY -- which can be slow
> 
> in mysql), you could use PHP's sort as well...
> 
> 
> 
> http://php.net/manual/en/function.natsort.php
> 
> 
> 
> > -Original Message-
> 
> > From: Robert Cummings [mailto:rob...@interjinn.com] 
> 
> > Sent: Saturday, January 16, 2010 9:37 PM
> 
> > To: John Taylor-Johnston
> 
> > Cc: PHP-General
> 
> > Subject: Re: [PHP] order by ASC
> 
> > 
> 
> > John Taylor-Johnston wrote:
> 
> > > Did some googling. This worked:
> 
> > > ORDER BY CAST(`rollnumber` AS SIGNED)
> 
> > > 
> 
> > > What is the difference? My problem in the meanwhile must be 
> 
> > my version 
> 
> > > of MySQL?
> 
> > 
> 
> > You could have skipped quotes altogether. The difference is 
> 
> > that you are 
> 
> > referencing a field name, not a string value.
> 
> > 
> 
> > Cheers,
> 
> > Rob.
> 
> > -- 
> 
> > http://www.interjinn.com
> 
> > Application and Templating Framework for PHP
> 
> > 
> 
> > -- 
> 
> > PHP General Mailing List (http://www.php.net/)
> 
> > To unsubscribe, visit: http://www.php.net/unsub.php
> 
> > 
> 
> 
> 
> 
> 
> 
> I've always found that ordering is much faster in MySQL than PHP. You use
> quite a lot of memory sorting in PHP as well, as you first have to load the
> whole result set into an array, which is additional to any memory used in
> the result set by PHP and MySQL anyway.
> 
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
>   
> 


I had a look at some of the results from that link to Google, but I
didn't see anything indicating MySQL was slower at ordering than PHP,
only that MySQL has issues ordering very large query sets on queries
that it cannot use an index to order on.

I've tried optimising ordering in both PHP and MySQL, and found that
usually it's best to leave as much to the database as possible, unless
the ordering becomes too complex.

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Cookies & sessions

2010-01-19 Thread clancy_1
On Tue, 19 Jan 2010 09:12:17 -0200, bsfaja...@gmail.com (Bruno Fajardo) wrote:

>2010/1/19  :
>> I am trying for the first time to use cookies. The manual contains the 
>> statement "Cookies
>> are part of the HTTP header, so setcookie() must be called before any output 
>> is sent to
>> the browser."
>>
>> When I first started using sessions, I was alarmed to read a very similar 
>> statement about
>> sessions, but I soon found that if I started my program with the statement
>> "session_start();" I could then set up, access, modify or clear any session 
>> variable at
>> any time in my program. This is enormously useful, as I can put the session 
>> handling at
>> any convenient point in my program, and can precede them with diagnostics if 
>> I need to.
>>
>> However I have almost immediately found that while I appear to be able to 
>> read cookies at
>> any time, I cannot set them when I would like to. Is there any similar trick 
>> which will
>> work with cookies?
>

>The only trick is that you have to call setcookie() before any output
>is sent to the browser, just like the session_start() behavior.
> ..

Thank you all for your suggestions.  Unfortunately I have already tried this, 
and it
doesn't work for me (I am running PHP: 5.1.6).  I have only tested this on my 
own PC, but
if it doesn't work here, I would be very surprised if it would work on the 
remote server.

Index.php starts:

http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Cookies & sessions

2010-01-19 Thread Phpster
The first setcookie call is empty which produces the errors that cause  
the second cookie to fail.


Bastien

Sent from my iPod

On Jan 19, 2010, at 10:16 PM, clanc...@cybec.com.au wrote:

On Tue, 19 Jan 2010 09:12:17 -0200, bsfaja...@gmail.com (Bruno  
Fajardo) wrote:



2010/1/19  :
I am trying for the first time to use cookies. The manual contains  
the statement "Cookies
are part of the HTTP header, so setcookie() must be called before  
any output is sent to

the browser."

When I first started using sessions, I was alarmed to read a very  
similar statement about
sessions, but I soon found that if I started my program with the  
statement
"session_start();" I could then set up, access, modify or clear  
any session variable at
any time in my program. This is enormously useful, as I can put  
the session handling at
any convenient point in my program, and can precede them with  
diagnostics if I need to.


However I have almost immediately found that while I appear to be  
able to read cookies at
any time, I cannot set them when I would like to. Is there any  
similar trick which will

work with cookies?





The only trick is that you have to call setcookie() before any output
is sent to the browser, just like the session_start() behavior.
..


Thank you all for your suggestions.  Unfortunately I have already  
tried this, and it
doesn't work for me (I am running PHP: 5.1.6).  I have only tested  
this on my own PC, but
if it doesn't work here, I would be very surprised if it would work  
on the remote server.


Index.php starts:

   Warning: Cannot modify header information - headers already sent by  
(output started at
D:\Websites\cypalda.com\index.php:4) in D:\Websites\cypalda.com 
\index.php on line 5


It is interesting to note that the second diagnostic is generated  
because the first
diagnostic is taken to have initiated the headers. I think I can  
live with this
limitation, but this diagnostic is a warning of the hassles I am  
likely to face if I

cannot find a way around it.


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



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



Re: [PHP] Cookies & sessions

2010-01-19 Thread clancy_1
On Tue, 19 Jan 2010 16:45:37 +0530, kranthi...@gmail.com (kranthi) wrote:

>> When I first started using sessions, I was alarmed to read a very similar 
>> statement about
>> sessions, but I soon found that if I started my program with the statement
>> "session_start();" I could then set up, access, modify or clear any session 
>> variable at
>> any time in my program. This is enormously useful, as I can put the session 
>> handling at
>> any convenient point in my program, and can precede them with diagnostics if 
>> I need to.
>
>are you looking for ob_* functions ?

Yes, thank you; I was!

I read this, and said "what the hell are they?", before I tried Bruno's 
setcookie() again,
and verified it didn't work. Then I noticed a textbook buried on my desk opened 
to the
section on cookies, saw "output buffering", and realised what you were talking 
about. And,
yes, they do seem to let me do what I want.

Unfortunately they don't do one thing I would have liked them to, which is to 
enable me to
see diagnostics buried in CSS code. The only way to discover these is to use 
the Explorer
'View source' option, and examine the HTML very carefully. While I was fiddling 
with the
setcookie suggestion some diagnostics went missing (because I was running the 
wrong
version), and when I looked at the HTML I found some error messages relating to 
an
undefined variable in the CSS, which I fear have been there for a long time.


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



[PHP] how to retrieve a dom from innerHTML......

2010-01-19 Thread I am on the top of the world! Borlange University
hello, i can obnot retrieve a select ject from div innerHTML.
what i want to do is that when a page is loaded, first selector,say #1,
would be shown in the first div by sending a request.then i choose one
option from #1, fire change event of #1, the second selector #2 will be
shown in div two, then choose option from #2 .blabla..

but the problem is when selector #1 was loaded, the object #1 could not be
obtained.
codes:

window.addEvent('domready', function() {

 var option=1;

 var result = new Request({
  
url:'getInfo_gx.php'
,
  method:'get',
  onSuccess:function(response)
  {
   if(option==1) $('list_sch').innerHTML = response; //response =
"

Re: [PHP] Cookies & sessions

2010-01-19 Thread clancy_1
On Tue, 19 Jan 2010 22:45:14 -0500, phps...@gmail.com (Phpster) wrote:

>The first setcookie call is empty which produces the errors that cause  
>the second cookie to fail.

I'm afraid not. I modified the program started to read:

http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] How do I remove unused GET parameters from the URL?

2010-01-19 Thread Daevid Vincent
I have an HTML form with a hundred or so elements on it, used for searching
a database.
 
When the user submits the form (via GET) the URL is loaded with ALL of
these fields, and many of them are not even actually used in the search
criteria.
 
https://mypse/dart2/ps_search.php?enter_date=2009-11-30&id_incident=&incide
nt_date=&incident_hh=0&incident_mm=0&id_urgency_level=0&problem_description
=&immediate_action=&unit_opened=&unit_authorized=&customer=&customer_contac
t=&customer_address=&customer_country=&id_location=0&passengers_onboard=&su
bmit=Search&part_number=&serial_number=&nomenclature=&manufacture_date=&mod
_level=&id_lru_condition=&repair_history=&ac_type=&tail_number=&id_system_t
ype=&id_lru_location=0&circuit_breaker=&circuit_breaker_amps=&seat_number=&
seat_vendor=&seat_column_zone=&seat_zone=&tc_holder=&stc_holder=&asr_mor=&i
mpounded=&id_authority=&id_region=&reported_by=&prepared_by=&preparer_locat
ion=&field_engineer=&id_attach_pictures=&id_attach_mlr=&id_attach_lopa=&cab
in_log=&parts_inspect=&id_organization=0&id_quality_engineer=0&car_number=&
close_date=&closed_by=&qa_comment=&id_priority=&id_action=0&id_incident_sta
tus=3&id_failure_type=&detail_status=&investigation_result=&osaka_action=&o
saka_request=&newvsrepeat=&related_incident=&unit_received_date=&unit_retur
ned_date=&tdr_to_pso_date=&tdr_date=&dcr_date=&dcr_reference_number=&ecr_da
te=&ecr_reference_number=&eco_date=&eco_reference_number=&service_bulletin_
date=&sb_reference_number=&sil_issue_date=&sil_reference_number=&til_issue_
date=&til_reference_number=&customer_letter_issue_date=&subassembly=&rdm=&p
svector=&oemmanuf=&defective_part_1=&defective_part_2=&defective_part_3=&de
fective_part_4=
 
Is there some way via PHP/Apache Mod/Javascript to remove all the keys that
don't have any value in them and just distill this down to the
elements/keys that the user actually entered some input for? ie. defaulting
all the rest to 'blank'.
 
In PHP, this would look something like this:
 
foreach ($_GET as $k => $v) if ($v == '') unset($_GET[$k]);
 
The problem as I see it, is that this "magic" happens when the user hits
"Submit", so not sure PHP has any way to intercept at that point.
Javascript might be able to do something on the "onClick" event or
"onSubmit" I suspect. But this seems like something that someone should
have solved before and common enough that I would think Apache could handle
it transparently with a directive or module enabled so I don't have to code
some hack on every page.
 
I guess I could always redirect to some 'scrubber' page that strips them
out and redirects on to the refering page again, but that seems klunky.
 
BTW, I want to use GET so that the page can be bookmarked for future
searches of the same data (or modified easily with different dates, etc.),
so that's why I don't use POST.


Re: [PHP] How do I remove unused GET parameters from the URL?

2010-01-19 Thread Michael A. Peters

Daevid Vincent wrote:
*snip*
 
The problem as I see it, is that this "magic" happens when the user hits

"Submit", so not sure PHP has any way to intercept at that point.
Javascript might be able to do something on the "onClick" event or
"onSubmit" I suspect. But this seems like something that someone should
have solved before and common enough that I would think Apache could handle
it transparently with a directive or module enabled so I don't have to code
some hack on every page.
 
I guess I could always redirect to some 'scrubber' page that strips them

out and redirects on to the refering page again, but that seems klunky.
 
BTW, I want to use GET so that the page can be bookmarked for future

searches of the same data (or modified easily with different dates, etc.),
so that's why I don't use POST.



JavaScript is the only client side way I know of.
Use document.getelementbyid() and yank the unused nodes before submit.

server side, redirect - it shouldn't be that clunky.
Put in a hidden input that tells your action script to redirect to 
itself without the unused get variables (and w/o the hidden input).


That's how I would do it personally (opposed to js).

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



Re: [PHP] How do I remove unused GET parameters from the URL?

2010-01-19 Thread Michael A. Peters

Daevid Vincent wrote:

 
I guess I could always redirect to some 'scrubber' page that strips them

out and redirects on to the refering page again, but that seems klunky.
 
BTW, I want to use GET so that the page can be bookmarked for future

searches of the same data (or modified easily with different dates, etc.),
so that's why I don't use POST.



Another option is to use post in the form, and when your action page 
receives post, it redirects to itself with the used variables as get.


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



Re: [PHP] 304 Not Modified header not working within a class

2010-01-19 Thread Camilo Sperberg
On Wed, Jan 20, 2010 at 02:33, Rene Veerman  wrote:

> if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND
> strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified) {
>
>
> shouldn't that be
>
> strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $last_modified)
>
> ?
>

Now that I think about it... yes; but I send the last modified header anyway
the first time (when $_SERVER['HTTP_IF_MODIFIED_SINCE'] == null):
header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).' GMT');

So if it isn't exactly equal, then the browser cache simply doesn't have the
latest version. It is impossible anyway that the browser can have a newer
version that doesn't previously exist on the server.
My best guess is that it doesn't affect the process: when I implement that
code in my class, it enters that part (meaning all the comparisons are ok)
but afterwards it keeps sending an "200 OK" header when I explicitly tell
Apache to send the "304 Not Modified" one.

Greetings and thanks for sharing :)

-- 
Mailed by:
UnReAl4U - unreal4u
ICQ #: 54472056
www1: http://www.chw.net/
www2: http://unreal4u.com/


Re: [PHP] PHP and javascript

2010-01-19 Thread Rene Veerman
To do what you want that new httpd server should at least be able to
call up PHP via cli / whatever, and retrieve the output.
It also needs to provide what's in php called $_GET and $_POST.

Assuming you got that covered, then yes, you could route the calls via
ajax (i recommend jquery.com for that) to your non-php httpd, which
then forwards it (and the results back).
What i'd do if it HAD to be done this way, is pass a couple of extra
variables in each call from javascript. It's best to route all the
ajax calls to php to the same script on the non-php httpd, so you'd
need at least the "relative path (from serverside defined absolute
base-path for your php subsystem) to the script being called" (or even
an MD5/SHA256 of this rel path, if you're on the paranoid side; you
then inform (via an array) the non-php httpd about all the scripts
that may be called from javascript, without giving up the scripts
names to spies along the line)

But tbh, whoever thought of changing the type of server used and
thereby giving you this new problem, should have also thought of how
to not-dump tons of existing code. Not to mention developer experience
with a specific language.

If this new httpd is so damn good at something that it has to be used,
it still doesn't mean it has to be used for the entire system either.
You might be giving it more work than it is comfortable with, that
way.

So depending on your backend size (in terms of number of machines
used) & setup, you might even campaign to keep an apache in the
picture and let it perform work on the database / file storage
system..

On Fri, Jan 15, 2010 at 8:07 PM, Andres Gonzalez  wrote:
> How do I call PHP code that will run server side, from javascript code that
> is running client side?
>
> I have a lot of PHP server side code written and working within CodeIgniter.
>  Now, my project
> has changed and (for reasons unimportant to this discussion) we are now NOT
> going to
> use apache and CodeIgniter, but instead, we are going to have to use an http
> server that does
> not support PHP internally.  But I want to reuse my original PHP code. So I
> am thinking that I
> can execute the PHP code via a command line interface using the PHP cli
> interface instead of
> the PHP cgi interface. But, I will have to initiate this serversid call via
> javascript code running
> on the client.
>
> I know...kind of convoluted. But how would one do this if necessary?
>
> -Andres
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] PHP and javascript

2010-01-19 Thread Rene Veerman
oh, and if you're going to use ajax->non-phphttpd->php->andback, then
check if your dear non-php httpd abuses the CPU while waiting for PHP
to return the results...

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



Re: [PHP] 304 Not Modified header not working within a class

2010-01-19 Thread Rene Veerman
ok, you might wanna re-ask on an apache list in that case..

On Wed, Jan 20, 2010 at 6:48 AM, Camilo Sperberg  wrote:
>
>
> On Wed, Jan 20, 2010 at 02:33, Rene Veerman  wrote:
>>
>> if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) AND
>> strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified) {
>>
>>
>> shouldn't that be
>>
>> strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) >= $last_modified)
>>
>> ?
>
> Now that I think about it... yes; but I send the last modified header anyway
> the first time (when $_SERVER['HTTP_IF_MODIFIED_SINCE'] == null):
> header('Last-Modified: '.gmdate('D, d M Y H:i:s',$last_modified).' GMT');
>
> So if it isn't exactly equal, then the browser cache simply doesn't have the
> latest version. It is impossible anyway that the browser can have a newer
> version that doesn't previously exist on the server.
> My best guess is that it doesn't affect the process: when I implement that
> code in my class, it enters that part (meaning all the comparisons are ok)
> but afterwards it keeps sending an "200 OK" header when I explicitly tell
> Apache to send the "304 Not Modified" one.
>
> Greetings and thanks for sharing :)
>
> --
> Mailed by:
> UnReAl4U - unreal4u
> ICQ #: 54472056
> www1: http://www.chw.net/
> www2: http://unreal4u.com/
>

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



Re: [PHP] 304 Not Modified header not working within a class

2010-01-19 Thread richard gray


Camilo Sperberg wrote:

Hi list, my first message here :)

To the point: I'm programming a class that takes several CSS files, parses,
compresses and saves into a cache file. However, I would like to go a step
further and also use the browser cache, handling the 304 and 200 header
types myself.

Now, what is the problem? If I do it within a function, there is absolutely
no problem, everything works like a charm. However, when I implement that
same concept into my class, there is no way I can send a 304 Not Modified
header, when the data is *over* ~100 bytes.

  

Hi Camilo

For what it is worth I have implemented cacheing in a class and for me 
the 304 not modified header gets sent fine ... some example headers 
output is below together with the relevant code snippet..


// See if client sent a page modified header to see if we can
// just send a not modified header instead
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && 
$_SERVER['HTTP_IF_MODIFIED_SINCE'] == self::$_gmmodtime) {

   header('HTTP/1.1 304 Not Modified');
   return null;
}

if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && 
stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == self::$_etag) {

   header('HTTP/1.1 304 Not Modified');
   return null;
}


HTTP/1.x 304 Not Modified
Date: Wed, 20 Jan 2010 07:21:32 GMT
Server: Apache/2.2.11 (Ubuntu)
Connection: Keep-Alive
Keep-Alive: timeout=5, max=1000
Etag: 444fbd9951f540ec1b6928db864c10dc
Expires: Sun, 24 Jan 2010 06:16:06 GMT
Cache-Control: public, must-revalidate
Vary: Accept-Encoding

I hope it helps..

Regards
Rich

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