php-general Digest 15 Jan 2010 01:46:58 -0000 Issue 6539

Topics (messages 301101 through 301123):

Re: header("Location:...") fails
        301101 by: haliphax

Re: Need Idea to make Backup
        301102 by: haliphax
        301104 by: Robert Cummings

php/ruby drb adapter
        301103 by: Pete Yadlowsky
        301119 by: Manuel Lemos

IDE -> SVN -> dev server -> live server
        301105 by: John Corry
        301106 by: vikash.iitb.gmail.com
        301110 by: Nathan Rixham

strtotime
        301107 by: John Taylor-Johnston
        301108 by: Ashley Sheridan
        301109 by: Adam Richardson
        301111 by: Kim Madsen
        301112 by: Adam Richardson
        301113 by: haliphax
        301120 by: John Taylor-Johnston

Re: To add the final ?> or not...
        301114 by: Kim Madsen
        301115 by: Kim Madsen
        301116 by: Ashley Sheridan
        301117 by: Kim Madsen
        301118 by: Ashley Sheridan
        301121 by: Kim Madsen
        301122 by: Ashley Sheridan
        301123 by: Bipper Goes!

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Wed, Jan 13, 2010 at 7:02 PM, Shawn McKenzie <[email protected]>wrote:

> Robert Cummings wrote:
> > Just make your life easy and create a redirect() function that generates
> > the header instruction, makes a relative URL into an absolute URL and
> > does the exit call. Then you just need to do:
> >
> > redirect( 'target.php' );
> >
> > Sooooooooo much simpler :)
> >
> > Cheers,
> > Rob.
>
> Definitely!  Technically, header() with Location: should have an
> absolute URL, though it works without one most of the time.
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Also, when in doubt, I find it's usually a good idea to check the output
being sent with a more low-level tool, such as Fiddler, so that you can view
the raw values rather than leaving it up to your browser to interpret them.


// Todd

--- End Message ---
--- Begin Message ---
On Thu, Jan 14, 2010 at 5:45 AM, Ashley Sheridan
<[email protected]>wrote:

> On Thu, 2010-01-14 at 12:32 +0100, Jens Geier wrote:
>
> > "Ashley Sheridan" <[email protected]> schrieb im Newsbeitrag
> > news:1263463572.5952.71.ca...@localhost...
> > > On Thu, 2010-01-14 at 10:12 +0100, Jens Geier wrote:
> > >
> > >> "Ashley Sheridan" <[email protected]> schrieb im Newsbeitrag
> > >> news:1263391167.5952.62.ca...@localhost...
> > >> > On Wed, 2010-01-13 at 14:57 +0100, Jens Geier wrote:
> > >> >
> > >> >> Hello Ashley,
> > >> >>
> > >> >> yes rsync is a good idea, but does this also work if there is only
> a
> > >> >> internet conection to may SERVER ?
> > >> >>
> > >> >> Kind Regards
> > >> >> Jens Geier
> > >> >>
> > >> >> "Ashley Sheridan" <[email protected]> schrieb im
> Newsbeitrag
> > >> >> news:1263377397.5952.60.ca...@localhost...
> > >> >> > On Wed, 2010-01-13 at 10:53 +0100, Jens Geier wrote:
> > >> >> >
> > >> >> >> Hello,
> > >> >> >>
> > >> >> >> my idea is to make a backup of some paths of my laptop via PHP.
> > >> >> >>
> > >> >> >> I like to use a MySQL Datebase to trace which file was uploaded
> > >> >> >> from
> > >> >> >> which
> > >> >> >> path and so on.
> > >> >> >>
> > >> >> >> Also it should be uses to look up it is nessasery to backup this
> > >> >> >> file
> > >> >> >> because it was changed since last time or not.
> > >> >> >>
> > >> >> >> All this files should be uploaded to the SERVER in a special
> folder
> > >> >> >> where
> > >> >> >> this files run to a tape backup machine.
> > >> >> >>
> > >> >> >> I hope some one can give me some ideas for this.
> > >> >> >>
> > >> >> >> Kind Regards
> > >> >> >> Jens Geier
> > >> >> >
> > >> >> > There's a few ways to go about doing this, but I reckon you
> should
> > >> >> > do
> > >> >> > something similar to the following:
> > >> >> >
> > >> >> >      * schedule a cron job to run as often as you want the backup
> to
> > >> >> > be
> > >> >> >        done, and have the cron call a script
> > >> >> >      * the script can either be php and use your own code to
> create
> > >> >> >        copies of files and check file dates for backup purposes,
> or
> > >> >> > use
> > >> >> >        the rsync tool which pretty much does all of this for you
> > >> >> >        automatically
> > >> >> >      * update a database as you need. this can be done either
> from a
> > >> >> >        php script or directly via mysql on the console
> > >> >> >
> > >> >> > If you do use PHP for this, you'll want to code it as a CLI
> script
> > >> >> > rather than a web page script. On the whole it won't make much of
> a
> > >> >> > difference, but obviously some global variables will change a
> bit.
> > >> >> >
> > >> >> > Thanks,
> > >> >> > Ash
> > >> >> > http://www.ashleysheridan.co.uk
> > >> >> >
> > >> >
> > >> > I don't understand what you mean?
> > >> >
> > >> > Ps, please try not to top-post.
> > >> >
> > >> > Thanks,
> > >> > Ash
> > >> > http://www.ashleysheridan.co.uk
> > >> >
> > >> Hello Ashley,
> > >>
> > >> i try to make a backup from some paths of my local laptop harddrive to
> a
> > >> folder on my server. Even if i'm not in the company.
> > >>
> > >> If i'm outside (this time i'm in China) i have to copy it through the
> > >> Internet that is using http or ftp transport protocol.
> > >>
> > >> The start of the copy is when the user clicks to a buttom and start
> the
> > >> backup process.
> > >>
> > >> Kind Regards
> > >> Jens Geier
> > >
> > > The script needs to be set up on your local machine. I don't think HTTP
> > > will help you much here, as that isn't great for transferring files
> > > upstream I've found. Googling 'rsync ftp example' brings about over
> > > 230,000 results, have you actually tried looking?
> > >
> > > Thanks,
> > > Ash
> > > http://www.ashleysheridan.co.uk
> > >
> > No, i have not.
> >
> > Because i also think that there will not a finish software.
> >
> > So i think i have to write something by my own.
> > That is the reason i ask for ideas to do so.
> >
> > I just read here the following thread:
> >
> > [PHP] Read directory; store filenames found in mySQL table?
> >
> > That is something that is running in that direction in try to go.
> >
> > Kind Regards
> > Jens Geier
> >
> >
> >
>
>
> But I've told you that the best tool to do it is rsync. This is a tool,
> not a whole large peice of software with a GUI, etc. You use it in
> conjunction with other software to achieve what you need. Have you even
> looked up at what rsync is?
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>

I recently used rsync (for the first time, even) in order to transfer an
entire directory structure of several thousand files and folders from one
VPS host to another. It worked like a dream, and the standard output could
be captured to build a report such as the OP was asking for.

Srsly, man -- take Ashley's suggestion and at least check it out. :)

--- End Message ---
--- Begin Message ---
haliphax wrote:
On Thu, Jan 14, 2010 at 5:45 AM, Ashley Sheridan
<[email protected]>wrote:

On Thu, 2010-01-14 at 12:32 +0100, Jens Geier wrote:

"Ashley Sheridan" <[email protected]> schrieb im Newsbeitrag
news:1263463572.5952.71.ca...@localhost...
On Thu, 2010-01-14 at 10:12 +0100, Jens Geier wrote:

"Ashley Sheridan" <[email protected]> schrieb im Newsbeitrag
news:1263391167.5952.62.ca...@localhost...
On Wed, 2010-01-13 at 14:57 +0100, Jens Geier wrote:

Hello Ashley,

yes rsync is a good idea, but does this also work if there is only
a
internet conection to may SERVER ?

Kind Regards
Jens Geier

"Ashley Sheridan" <[email protected]> schrieb im
Newsbeitrag
news:1263377397.5952.60.ca...@localhost...
On Wed, 2010-01-13 at 10:53 +0100, Jens Geier wrote:

Hello,

my idea is to make a backup of some paths of my laptop via PHP.

I like to use a MySQL Datebase to trace which file was uploaded
from
which
path and so on.

Also it should be uses to look up it is nessasery to backup this
file
because it was changed since last time or not.

All this files should be uploaded to the SERVER in a special
folder
where
this files run to a tape backup machine.

I hope some one can give me some ideas for this.

Kind Regards
Jens Geier
There's a few ways to go about doing this, but I reckon you
should
do
something similar to the following:

     * schedule a cron job to run as often as you want the backup
to
be
       done, and have the cron call a script
     * the script can either be php and use your own code to
create
       copies of files and check file dates for backup purposes,
or
use
       the rsync tool which pretty much does all of this for you
       automatically
     * update a database as you need. this can be done either
from a
       php script or directly via mysql on the console

If you do use PHP for this, you'll want to code it as a CLI
script
rather than a web page script. On the whole it won't make much of
a
difference, but obviously some global variables will change a
bit.
Thanks,
Ash
http://www.ashleysheridan.co.uk

I don't understand what you mean?

Ps, please try not to top-post.

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

Hello Ashley,

i try to make a backup from some paths of my local laptop harddrive to
a
folder on my server. Even if i'm not in the company.

If i'm outside (this time i'm in China) i have to copy it through the
Internet that is using http or ftp transport protocol.

The start of the copy is when the user clicks to a buttom and start
the
backup process.

Kind Regards
Jens Geier
The script needs to be set up on your local machine. I don't think HTTP
will help you much here, as that isn't great for transferring files
upstream I've found. Googling 'rsync ftp example' brings about over
230,000 results, have you actually tried looking?

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

No, i have not.

Because i also think that there will not a finish software.

So i think i have to write something by my own.
That is the reason i ask for ideas to do so.

I just read here the following thread:

[PHP] Read directory; store filenames found in mySQL table?

That is something that is running in that direction in try to go.

Kind Regards
Jens Geier




But I've told you that the best tool to do it is rsync. This is a tool,
not a whole large peice of software with a GUI, etc. You use it in
conjunction with other software to achieve what you need. Have you even
looked up at what rsync is?

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


I recently used rsync (for the first time, even) in order to transfer an
entire directory structure of several thousand files and folders from one
VPS host to another. It worked like a dream, and the standard output could
be captured to build a report such as the OP was asking for.

Srsly, man -- take Ashley's suggestion and at least check it out. :)

I've been using rsnapshot (it uses rsync) to do backups of remote server directories:

     http://rsnapshot.org/

Just thought I'd throw it out there :)

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

--- End Message ---
--- Begin Message ---

Hi,

I'll be honest: php is not my favorite programming language. That honor goes to ruby. And I don't mean ruby-on-rails; just straight, pure unfettered ruby. I use ruby to write web applications and just about everything else.

However, there are obviously very many web applications and webapp frameworks written in php. I have recently taken an interest in eyeOS (http://eyeos.org/), with the intent to hack eyeOS to use a certain ruby back-end file service I've written instead of accessing the local file system directly. This ruby service communicates with clients via ruby's native "distributed ruby" (DRb) facility. DRb makes it marvelously easy to write distributed multi-threaded services, provided the clients are written in ruby as well.

But what if the client is written in, say, php? Wouldn't it be nice if a php client could access DRb-driven ruby services just as simply as a ruby client can? Not finding any such existing facility, I've written a php object class, "DRbClient". This class invokes object methods offered by the remote ruby service, passing strings, integers, floats, booleans, nulls, and/or arrays as arguments, and accepts a return value of any of those same types. All data translation and inter-process communication is transparent. It's just as if a local object instance is being messaged directly.

If there's interest, I'd like to offer DRbClient to the php community, but I'm not sure how to go about that.

--
Pete Yadlowsky
ITC Unix Systems Support
University of Virginia

--- End Message ---
--- Begin Message ---
Hello,

on 01/14/2010 12:51 PM Pete Yadlowsky said the following:
> I'll be honest: php is not my favorite programming language. That honor
> goes to ruby. And I don't mean ruby-on-rails; just straight, pure
> unfettered ruby. I use ruby to write web applications and just about
> everything else.
> 
> However, there are obviously very many web applications and webapp
> frameworks written in php. I have recently taken an interest in eyeOS
> (http://eyeos.org/), with the intent to hack eyeOS to use a certain ruby
> back-end file service I've written instead of accessing the local file
> system directly. This ruby service communicates with clients via ruby's
> native "distributed ruby" (DRb) facility. DRb makes it marvelously easy
> to write distributed multi-threaded services, provided the clients are
> written in ruby as well.
> 
> But what if the client is written in, say, php? Wouldn't it be nice if a
> php client could access DRb-driven ruby services just as simply as a
> ruby client can? Not finding any such existing facility, I've written a
> php object class, "DRbClient". This class invokes object methods offered
> by the remote ruby service, passing strings, integers, floats, booleans,
> nulls, and/or arrays as arguments, and accepts a return value of any of
> those same types. All data translation and inter-process communication
> is transparent. It's just as if a local object instance is being
> messaged directly.
> 
> If there's interest, I'd like to offer DRbClient to the php community,
> but I'm not sure how to go about that.

If that is based in a class written in PHP, you may want to submit it to
PHPClasses.org . It has hundreds of thousands of registered users eager
to learn about new PHP classes.

http://www.phpclasses.org/

As for distributing processing over multiple threads running eventually
on different machines, that sounds more like a job for Gearman.

http://www.phpclasses.org/blog/post/108-Distributing-PHP-processing-with-Gearman.html

-- 

Regards,
Manuel Lemos

Find and post PHP jobs
http://www.phpclasses.org/jobs/

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

--- End Message ---
--- Begin Message ---
I am working on designing an documenting a process for our team to use to
manage code updates/changes.

What we've been doing has been ghastly: a bunch of developers using
dreamweaver's 'check in/out' functions, all using the same FTP login, to FTP
files to the production server.

It turns out the site we're working on together is a bit too complex for
this, so it's on me to come up with a better way.

I'm a big fan of SVN and think we'll be light years ahead of where we are
presently by using SVN to manage code revisions.

So, I've set up an SVN repository on our dedicated server and imported all
of the live-site code. Then I set up a dev virtual host (dev.domain.com) and
exported all of the code in my repository to that vhost's DocRoot. So...that
gave me a copy. Next, I copied the MySQL db to a separate db that we'll use
for the dev server...so dev code doesn't query the live db. Then of course,
I had to edit the config files that have DSN information in them to make
sure my dev site actually uses my dev db.

Here's where the problems start to creep in...

If I export the whole repository from SVN to the dev DocRoot directory, I'm
going to overwrite the config files that have DSN info in them. Similarly,
there are some javascript files that declare variables like var base_url = '
http://mysite.com'...those variables need to be set once for the environment
(my local IDE? the dev server? the production server?) and then not messed
with afterward.

After an SVN commit, it's really easy to svn export svn://localhost/mysite
/path/to/my/dev_server

Simple, all of the code in the repository goes to the dev server.

The issue I'm having is that there are a number of files that I do NOT want
to be copied from the repository to the dev server, except on
rare occasions.

So, I can choose to add the files to my svn:ignore in my working copy so
they aren't committed/updated. But I can't ensure that all of the developers
take this step and it's not a reliable way to keep those select files in the
repository out of my dev server.

Or, I can write a shell script that does the SVN export, then overwrites the
selected config files with master versions that are stored somewhere else
and not edited by any of the team. One problem with that though, is that our
main javascript file tends to be edited/changed and it's one that can create
problems if that base_url var isn't appropriate to the server it's on.

Or, in all of my PHP files, I can write the config values into switch
statements:
switch($_SERVER['HTTP_HOST']) {
  case 'mysite.local':
     // local IDE config directives
  case 'dev.mysite.com':
     // dev server config directives
  // etc...
}

...but that leaves the production server DSN sitting around in development
code, which I'd like to avoid, and I don't have an analogous solution for my
javascript files.

JS question: is there a js way to do the same thing? Evaluate the js
equivalent of PHP's $_SERVER['HTTP_HOST']? If there is, I think this
solution will work.

This has got to be a fairly typical workflow and problem.

What are some of the strategies you folks use for designing your flow of
code from local IDE to SVN to dev server to production server?

-- 
John Corry
PHP developer - 3by400, Inc
http://www.3by400.com

--- End Message ---
--- Begin Message ---
I do not see the reason why you would need an absolute URL like var base_url
= '
http://mysite.com' in your javascript code.

If only this is giving you problems, use: *window.location.hostname* to get
the hostname in javascript.

---
Vikash Kumar
http://vika.sh


On Thu, Jan 14, 2010 at 9:40 PM, John Corry <[email protected]> wrote:

> I am working on designing an documenting a process for our team to use to
> manage code updates/changes.
>
> What we've been doing has been ghastly: a bunch of developers using
> dreamweaver's 'check in/out' functions, all using the same FTP login, to
> FTP
> files to the production server.
>
> It turns out the site we're working on together is a bit too complex for
> this, so it's on me to come up with a better way.
>
> I'm a big fan of SVN and think we'll be light years ahead of where we are
> presently by using SVN to manage code revisions.
>
> So, I've set up an SVN repository on our dedicated server and imported all
> of the live-site code. Then I set up a dev virtual host (dev.domain.com)
> and
> exported all of the code in my repository to that vhost's DocRoot.
> So...that
> gave me a copy. Next, I copied the MySQL db to a separate db that we'll use
> for the dev server...so dev code doesn't query the live db. Then of course,
> I had to edit the config files that have DSN information in them to make
> sure my dev site actually uses my dev db.
>
> Here's where the problems start to creep in...
>
> If I export the whole repository from SVN to the dev DocRoot directory, I'm
> going to overwrite the config files that have DSN info in them. Similarly,
> there are some javascript files that declare variables like var base_url =
> '
> http://mysite.com'...those variables need to be set once for the
> environment
> (my local IDE? the dev server? the production server?) and then not messed
> with afterward.
>
> After an SVN commit, it's really easy to svn export svn://localhost/mysite
> /path/to/my/dev_server
>
> Simple, all of the code in the repository goes to the dev server.
>
> The issue I'm having is that there are a number of files that I do NOT want
> to be copied from the repository to the dev server, except on
> rare occasions.
>
> So, I can choose to add the files to my svn:ignore in my working copy so
> they aren't committed/updated. But I can't ensure that all of the
> developers
> take this step and it's not a reliable way to keep those select files in
> the
> repository out of my dev server.
>
> Or, I can write a shell script that does the SVN export, then overwrites
> the
> selected config files with master versions that are stored somewhere else
> and not edited by any of the team. One problem with that though, is that
> our
> main javascript file tends to be edited/changed and it's one that can
> create
> problems if that base_url var isn't appropriate to the server it's on.
>
> Or, in all of my PHP files, I can write the config values into switch
> statements:
> switch($_SERVER['HTTP_HOST']) {
>  case 'mysite.local':
>     // local IDE config directives
>  case 'dev.mysite.com':
>     // dev server config directives
>  // etc...
> }
>
> ...but that leaves the production server DSN sitting around in development
> code, which I'd like to avoid, and I don't have an analogous solution for
> my
> javascript files.
>
> JS question: is there a js way to do the same thing? Evaluate the js
> equivalent of PHP's $_SERVER['HTTP_HOST']? If there is, I think this
> solution will work.
>
> This has got to be a fairly typical workflow and problem.
>
> What are some of the strategies you folks use for designing your flow of
> code from local IDE to SVN to dev server to production server?
>
> --
> John Corry
> PHP developer - 3by400, Inc
> http://www.3by400.com
>

--- End Message ---
--- Begin Message ---
John Corry wrote:
> I am working on designing an documenting a process for our team to use to
> manage code updates/changes.
> 
> What we've been doing has been ghastly: a bunch of developers using
> dreamweaver's 'check in/out' functions, all using the same FTP login, to FTP
> files to the production server.
> 
> It turns out the site we're working on together is a bit too complex for
> this, so it's on me to come up with a better way.
> 
> I'm a big fan of SVN and think we'll be light years ahead of where we are
> presently by using SVN to manage code revisions.
> 
> So, I've set up an SVN repository on our dedicated server and imported all
> of the live-site code. Then I set up a dev virtual host (dev.domain.com) and
> exported all of the code in my repository to that vhost's DocRoot. So...that
> gave me a copy. Next, I copied the MySQL db to a separate db that we'll use
> for the dev server...so dev code doesn't query the live db. Then of course,
> I had to edit the config files that have DSN information in them to make
> sure my dev site actually uses my dev db.
> 
> Here's where the problems start to creep in...
> 
> If I export the whole repository from SVN to the dev DocRoot directory, I'm
> going to overwrite the config files that have DSN info in them. Similarly,
> there are some javascript files that declare variables like var base_url = '
> http://mysite.com'...those variables need to be set once for the environment
> (my local IDE? the dev server? the production server?) and then not messed
> with afterward.
> 
> After an SVN commit, it's really easy to svn export svn://localhost/mysite
> /path/to/my/dev_server
> 
> Simple, all of the code in the repository goes to the dev server.
> 
> The issue I'm having is that there are a number of files that I do NOT want
> to be copied from the repository to the dev server, except on
> rare occasions.
> 
> So, I can choose to add the files to my svn:ignore in my working copy so
> they aren't committed/updated. But I can't ensure that all of the developers
> take this step and it's not a reliable way to keep those select files in the
> repository out of my dev server.
> 
> Or, I can write a shell script that does the SVN export, then overwrites the
> selected config files with master versions that are stored somewhere else
> and not edited by any of the team. One problem with that though, is that our
> main javascript file tends to be edited/changed and it's one that can create
> problems if that base_url var isn't appropriate to the server it's on.
> 
> Or, in all of my PHP files, I can write the config values into switch
> statements:
> switch($_SERVER['HTTP_HOST']) {
>   case 'mysite.local':
>      // local IDE config directives
>   case 'dev.mysite.com':
>      // dev server config directives
>   // etc...
> }
> 
> ...but that leaves the production server DSN sitting around in development
> code, which I'd like to avoid, and I don't have an analogous solution for my
> javascript files.
> 
> JS question: is there a js way to do the same thing? Evaluate the js
> equivalent of PHP's $_SERVER['HTTP_HOST']? If there is, I think this
> solution will work.
> 
> This has got to be a fairly typical workflow and problem.
> 
> What are some of the strategies you folks use for designing your flow of
> code from local IDE to SVN to dev server to production server?
> 

personally I just use a switch and a couple of sh scripts to roll out;
for the development environment I run the update-dev.sh script as an svn
commit hook so dev is updated on every commit; for uat/live it's
requires a manual run of ./update-live.sh (in reality i actually use
phpUnderControl for continuous build automation and it only rolls out to
live when a build/revision passes all unit tests).

To deal with custom files per site; I keep all user submitted
site-specific content in separate storage directories outside of the web
root which solves half the problem; and for the remaining
config/htaccess/cache files its just a case of using a few lines of bash
script to ensure domain specific stuff isn't wiped out on roll-out.

on the HTTP_HOST side of things I personally try to negate the use of
domains in urls wherever possible opting for /path/to/file.js instead -
but when it does creep up you can easily negotiate then by doing a
simple string replace:

define( 'DOMAIN' , 'clientsite.com' );

function u( $uri )
{
 return str_replace(DOMAIN, 'http://'.$_SERVER['HTTP_HOST'].'/', $uri);
}

echo u( 'http://clientsite.com/some-page/' );

and on the js side you could use document.domain or
window.location.hostname or suchlike

ps non of this is worth arguing over, just something to get you going
and filed under "works for me"

--- End Message ---
--- Begin Message ---
Hello,

In a mysql date() field, I set the default to "0000-00-00".

Therefore, $mydata->birthday = "0000-00-00";

But when I run this next line, $then = 1969.

$then=date("Y", strtotime($mydata->birthday));

Why 1969, and not 0 or nothing?

If I  echo strtotime("0000-00-00");

Nothing appears. So $then should be nothing?

What is wrong with my logic?

Thanks,
John

--- End Message ---
--- Begin Message ---
On Thu, 2010-01-14 at 13:14 -0500, John Taylor-Johnston wrote:

> Hello,
> 
> In a mysql date() field, I set the default to "0000-00-00".
> 
> Therefore, $mydata->birthday = "0000-00-00";
> 
> But when I run this next line, $then = 1969.
> 
> $then=date("Y", strtotime($mydata->birthday));
> 
> Why 1969, and not 0 or nothing?
> 
> If I  echo strtotime("0000-00-00");
> 
> Nothing appears. So $then should be nothing?
> 
> What is wrong with my logic?
> 
> Thanks,
> John
> 


MySQL uses a default "0000-00-00" value for date fields generally, but
when converted into a timestamp, the string equates to a false value. In
PHP, timestamps are numerical values indicating the seconds since
Midnight of the 1st January 1969. As PHP uses loose data typing, false
is converted to a 0 (zero),and strtotime("0000-00-00") returns false. As
such, it is treated as the date when time began (for the PHP date object
at least).

There's nothing wrong with your logic, but if you want to check for
empty values, then you should use an extra if statement to check if
strtotime("0000-00-00") === false

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



--- End Message ---
--- Begin Message ---
When you set the date to "0000-00-00", you start the following sequence:


   1. strtotime returns false, because "0000-00-00" isn't a date it can
   parse into a timestamp.
   2. date returns 1969, because it's not passed a valid timestamp and it
   works from December 31, 1969 for any invalid date.


On Thu, Jan 14, 2010 at 1:14 PM, John Taylor-Johnston <
[email protected]> wrote:

> Hello,
>
> In a mysql date() field, I set the default to "0000-00-00".
>
> Therefore, $mydata->birthday = "0000-00-00";
>
> But when I run this next line, $then = 1969.
>
> $then=date("Y", strtotime($mydata->birthday));
>
> Why 1969, and not 0 or nothing?
>
> If I  echo strtotime("0000-00-00");
>
> Nothing appears. So $then should be nothing?
>
> What is wrong with my logic?
>
> Thanks,
> John
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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

--- End Message ---
--- Begin Message ---
Hi guys

I have a question:

<snip>
Ashley Sheridan wrote on 14/01/2010 19:20:
MySQL uses a default "0000-00-00" value for date fields generally, but
when converted into a timestamp, the string equates to a false value. In
PHP, timestamps are numerical values indicating the seconds since
Midnight of the 1st January 1969. As PHP uses loose data typing, false
</snip>

Adam Richardson wrote on 14/01/2010 19:25:
<snip>
2. date returns 1969, because it's not passed a valid timestamp and it works from December 31, 1969 for any invalid date.
</snip>

Why is this? Unixtime starts at January 1st 1970 GMT (see for instance http://php.net/microtime), I've never heard of the other dates you mentioned.

My guess is the time, date or GMT is wrong for Johns setup and that's why he get 1969 and not 1970, cause something is seting time in the past

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
I've not read this, but if the first valid date is Jan. 1st, 1970, then
passing that date back in the case of errors would lead to ambiguity.  Is it
a valid date or is it an error.  Passing back the date of the day just
before (in terms of time, I think it's the second before) the first valid
date lets you easily identify an error.

Again, I didn't read this anywhere, though, and I could be wrong.

Adam

On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen <[email protected]> wrote:

> Hi guys
>
> I have a question:
>
> <snip>
> Ashley Sheridan wrote on 14/01/2010 19:20:
>
> MySQL uses a default "0000-00-00" value for date fields generally, but
> when converted into a timestamp, the string equates to a false value. In
> PHP, timestamps are numerical values indicating the seconds since
> Midnight of the 1st January 1969. As PHP uses loose data typing, false
> </snip>
>
> Adam Richardson wrote on 14/01/2010 19:25:
> <snip>
> 2. date returns 1969, because it's not passed a valid timestamp and it
> works from December 31, 1969 for any invalid date.
> </snip>
>
> Why is this? Unixtime starts at January 1st 1970 GMT (see for instance
> http://php.net/microtime), I've never heard of the other dates you
> mentioned.
>
> My guess is the time, date or GMT is wrong for Johns setup and that's why
> he get 1969 and not 1970, cause something is seting time in the past
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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

--- End Message ---
--- Begin Message ---
On Thu, Jan 14, 2010 at 2:53 PM, Adam Richardson <[email protected]>wrote:

> I've not read this, but if the first valid date is Jan. 1st, 1970, then
> passing that date back in the case of errors would lead to ambiguity.  Is
> it
> a valid date or is it an error.  Passing back the date of the day just
> before (in terms of time, I think it's the second before) the first valid
> date lets you easily identify an error.
>
> Again, I didn't read this anywhere, though, and I could be wrong.
>
> Adam
>
> On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen <[email protected]> wrote:
>
> > Hi guys
> >
> > I have a question:
> >
> > <snip>
> > Ashley Sheridan wrote on 14/01/2010 19:20:
> >
> > MySQL uses a default "0000-00-00" value for date fields generally, but
> > when converted into a timestamp, the string equates to a false value. In
> > PHP, timestamps are numerical values indicating the seconds since
> > Midnight of the 1st January 1969. As PHP uses loose data typing, false
> > </snip>
> >
> > Adam Richardson wrote on 14/01/2010 19:25:
> > <snip>
> > 2. date returns 1969, because it's not passed a valid timestamp and it
> > works from December 31, 1969 for any invalid date.
> > </snip>
> >
> > Why is this? Unixtime starts at January 1st 1970 GMT (see for instance
> > http://php.net/microtime), I've never heard of the other dates you
> > mentioned.
> >
> > My guess is the time, date or GMT is wrong for Johns setup and that's why
> > he get 1969 and not 1970, cause something is seting time in the past
>

Time zones. If I have PHP spit out a date for "0" as a string on my system,
it comes back as 18:00 on December 31st, 1969, because I am in the Central
time zone.

// Todd

--- End Message ---
--- Begin Message ---
My thanks to all!

Adam Richardson wrote:
I've not read this, but if the first valid date is Jan. 1st, 1970, then passing that date back in the case of errors would lead to ambiguity. Is it a valid date or is it an error. Passing back the date of the day just before (in terms of time, I think it's the second before) the first valid date lets you easily identify an error.

Again, I didn't read this anywhere, though, and I could be wrong.

Adam

On Thu, Jan 14, 2010 at 3:47 PM, Kim Madsen <php.net <http://php.net>@emax.dk <http://emax.dk>> wrote:

    Hi guys

    I have a question:

    <snip>
    Ashley Sheridan wrote on 14/01/2010 19:20:

    MySQL uses a default "0000-00-00" value for date fields generally, but
    when converted into a timestamp, the string equates to a false
    value. In
    PHP, timestamps are numerical values indicating the seconds since
    Midnight of the 1st January 1969. As PHP uses loose data typing, false
    </snip>

    Adam Richardson wrote on 14/01/2010 19:25:
    <snip>
    2. date returns 1969, because it's not passed a valid timestamp
    and it works from December 31, 1969 for any invalid date.
    </snip>

    Why is this? Unixtime starts at January 1st 1970 GMT (see for
    instance http://php.net/microtime), I've never heard of the other
    dates you mentioned.

    My guess is the time, date or GMT is wrong for Johns setup and
    that's why he get 1969 and not 1970, cause something is seting
    time in the past

-- Kind regards
    Kim Emax - masterminds.dk <http://masterminds.dk>


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




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

--- End Message ---
--- Begin Message ---
Hey

Haven't had the time to read up on the maillist, but here's my input.

Mattias Thorslund wrote on 09/01/2010 02:26:

To my eyes, ?> means "look there is more content coming", which seems kind of silly when there isn't.

To mine it means, no more PHP code for now. I don't wanna make it diffenrent from a file containing pure PHP code or one that contains both PHP and HTML, where I jump in and out of the PHP tag.

Remember the ?> stops the parser

And I find it bad coding standard to start a tag and not end it, even if it's possible. Remember Perl is a smart, but also terrible language, where one can leave out the ; in the end of a oneline script and make a bunch of stuff on $_ without showing what variable you're working on.

And finally, mysql_close() was always called after a script was closed, so I've never learned to practice that and for the last ten years I've seen only _one_ developer added that function call to the end of his files. In PHP6 that call is required, so making the cleanest code is in my opinion more readable and also more correct, since you'll never know what the PHP core team will come up with next ;-)

A neat thing with pairing every <?php with a ?> when mixed in HTML is that these are valid XML processing instructions. If your HTML satisfies XML well-formedness, your PHP document will also be valid XML. Not that I've ever had any need to process my layout templates as XML but anyway.

I don't see your argument. PHP generates HTML or XML files. When you're aware of the XML tag of course you make sure the XML file generated is valid. Why would you ever add PHP code to a HTML file (other than for documentation, examples etc.)?

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
John Corry wrote on 12/01/2010 17:04:
I leave ?> out.

I'm pretty careful about my code formatting and whitespace.

It's my opinion that if I can eliminate a potential problem by not including
an optional closing tag...there's really no reason why I shouldn't.

What is the difference between:

<?
print "hello PHPeople";
?>WHITESPACE

and

<?
print "hello PHPeople";
WHITESPACE

Same shit when I look at it, a sloppy developer is what it is :-)

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
On Thu, 2010-01-14 at 23:30 +0100, Kim Madsen wrote:

> John Corry wrote on 12/01/2010 17:04:
> > I leave ?> out.
> > 
> > I'm pretty careful about my code formatting and whitespace.
> > 
> > It's my opinion that if I can eliminate a potential problem by not including
> > an optional closing tag...there's really no reason why I shouldn't.
> 
> What is the difference between:
> 
> <?
> print "hello PHPeople";
> ?>WHITESPACE
> 
> and
> 
> <?
> print "hello PHPeople";
> WHITESPACE
> 
> Same shit when I look at it, a sloppy developer is what it is :-)
> 
> -- 
> Kind regards
> Kim Emax - masterminds.dk
> 


Plenty of differences, if you include the first one as a file, the
whitespace gets sent to the browser because it is not part of the PHP,
and so is assumed to be HTML. Once this happens, the headers have been
sent, so you can't use different headers in your script.

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



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote on 14/01/2010 23:30:

What is the difference between:

<?
print "hello PHPeople";
?>WHITESPACE

and

<?
print "hello PHPeople";
WHITESPACE

Same shit when I look at it, a sloppy developer is what it is :-)

--
Kind regards
Kim Emax - masterminds.dk


Plenty of differences, if you include the first one as a file, the whitespace gets sent to the browser because it is not part of the PHP, and so is assumed to be HTML. Once this happens, the headers have been sent, so you can't use different headers in your script.

Hmm... you could be right. I guess I just never made that mistake :-)
--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
On Thu, 2010-01-14 at 23:37 +0100, Kim Madsen wrote:

> Ashley Sheridan wrote on 14/01/2010 23:30:
> 
> >> What is the difference between:
> >>
> >> <?
> >> print "hello PHPeople";
> >> ?>WHITESPACE
> >>
> >> and
> >>
> >> <?
> >> print "hello PHPeople";
> >> WHITESPACE
> >>
> >> Same shit when I look at it, a sloppy developer is what it is :-)
> >>
> >> -- 
> >> Kind regards
> >> Kim Emax - masterminds.dk
> >>
> > 
> > Plenty of differences, if you include the first one as a file, the 
> > whitespace gets sent to the browser because it is not part of the PHP, 
> > and so is assumed to be HTML. Once this happens, the headers have been 
> > sent, so you can't use different headers in your script.
> 
> Hmm... you could be right. I guess I just never made that mistake :-)
> -- 
> Kind regards
> Kim Emax - masterminds.dk
> 


What has been said on this thread a few times is it is not always a
developer error, but a bug with the editor, which is not something that
will be picked up until it occurs.

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



--- End Message ---
--- Begin Message ---
Ashley Sheridan wrote on 14/01/2010 23:36:

What has been said on this thread a few times is it is not always a developer error, but a bug with the editor, which is not something that will be picked up until it occurs.

Once again I love my VIm :-) (with whitespace highlight if needed)

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
On Fri, 2010-01-15 at 00:04 +0100, Kim Madsen wrote:

> Ashley Sheridan wrote on 14/01/2010 23:36:
> 
> > What has been said on this thread a few times is it is not always a 
> > developer error, but a bug with the editor, which is not something that 
> > will be picked up until it occurs.
> 
> Once again I love my VIm :-) (with whitespace highlight if needed)
> 
> -- 
> Kind regards
> Kim Emax - masterminds.dk
> 


I'm a fan of Kate myself, can recognise pretty much any language you
throw at it, and has a couple of neat plugins for web development

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



--- End Message ---
--- Begin Message ---
Wait, Kim, whats your last name?

On Thu, Jan 14, 2010 at 5:04 PM, Kim Madsen <[email protected]> wrote:

> Ashley Sheridan wrote on 14/01/2010 23:36:
>
>
>  What has been said on this thread a few times is it is not always a
>> developer error, but a bug with the editor, which is not something that will
>> be picked up until it occurs.
>>
>
> Once again I love my VIm :-) (with whitespace highlight if needed)
>
>
> --
> Kind regards
> Kim Emax - masterminds.dk
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---

Reply via email to