php-general Digest 3 Feb 2009 16:27:23 -0000 Issue 5938
Topics (messages 287557 through 287565):
Re: PHP Linux/Windows Outlook 2003 HTML email problem
287557 by: German Geek
Visibility of class constant
287558 by: leledumbo
287563 by: Chris Scott
Throwing an exception seems to defeat output buffering
287559 by: Leif Wickland
287561 by: Ondrej Kulaty
287562 by: Colin Guthrie
Re: How can I do the opposite of property_exists(), maybe a creat_property() in
PHP5?
287560 by: Edmund Hertle
287564 by: Jochem Maas
calculate the time that day ends
287565 by: Thodoris
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
It seems like this solves the issue:
http://pear.php.net/bugs/bug.php?id=12032 Sorry, just hadn't found this
before.
Tim-Hinnerk Heuer
http://www.ihostnz.com
On Mon, Feb 2, 2009 at 7:24 PM, Chris <dmag...@gmail.com> wrote:
> German Geek wrote:
>
>> Hi All,
>>
>> We've got a problem with our Ubuntu Linux machine sending HTML emails to
>> Outlook 2003:
>>
>> It's an Ubuntu Server (uname -a
>> Linux CDR2-221 2.6.24-19-server #1 SMP Wed Jun 18 15:18:00 UTC 2008 i686
>> GNU/Linux)
>>
>> with the newest version of Postfix installed as the Mail server.
>>
>> Unfortunately, all emails sent as HTML, using the PEAR library for sending
>> email like so:
>>
>
> Best place to look at this would be the pear list:
>
> http://pear.php.net/support/lists.php
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
--- End Message ---
--- Begin Message ---
I got a weird behaviour of class constant. Suppose I have Index_Controller
and Another_Controller classes, both extending Controller class. I define
some constants (let's assume I only have one, call it MY_CONST) in
Controller class to be used by its descendants. In Index_Controller, I can
freely use MY_CONST without parent:: needed. However, this isn't the case
with Another_Controller. Without parent:: I got notice Use of undefined
constant MY_CONST - assumed 'MY_CONST'. How could this happen and what's the
correct behaviour? It's actually nicer to have it without parent::, assuming
that constants have protected visibility specifier (which isn't possible
AFAIK :-( ).
--
View this message in context:
http://www.nabble.com/Visibility-of-class-constant-tp21803985p21803985.html
Sent from the PHP - General mailing list archive at Nabble.com.
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: leledumbo [mailto:leledumbo_c...@yahoo.co.id]
> Sent: 03 February 2009 05:03
> To: php-gene...@lists.php.net
> Subject: [PHP] Visibility of class constant
>
>
> I got a weird behaviour of class constant. Suppose I have
Index_Controller
> and Another_Controller classes, both extending Controller class. I
define
> some constants (let's assume I only have one, call it MY_CONST) in
> Controller class to be used by its descendants. In Index_Controller, I
can
> freely use MY_CONST without parent:: needed. However, this isn't the
case
> with Another_Controller. Without parent:: I got notice Use of
undefined
> constant MY_CONST - assumed 'MY_CONST'. How could this happen and
what's the
> correct behaviour? It's actually nicer to have it without parent::,
assuming
> that constants have protected visibility specifier (which isn't
possible
> AFAIK :-( ).
You cannot access a class constant just by the constant name. See
http://docs.php.net/manual/en/language.oop5.paamayim-nekudotayim.php.
you need to use self::MY_CONST, I guess; your code might make it
clearer.
e.g.
class Controller
{
const CONSTANT = 'foo<br />';
}
class Index_Controller extends Controller
{
public function __construct()
{
echo CONSTANT; echo '<br/>'; // gives warning
echo self::CONSTANT; // foo
echo parent::CONSTANT; // foo
}
}
class Another_Controller extends Controller
{
const CONSTANT = 'bar<br />';
public function __construct()
{
echo self::CONSTANT; // bar
echo parent::CONSTANT; // foo
}
}
new Index_Controller would give you the warning you described for
CONSTANT and return 'foo' for self::CONSTANT and parent::CONSTANT as
CONSTANT was inherited. In Another_Controller CONSTANT is overridden so
self::CONSTANT would be 'bar' and parent::CONSTANT would be 'foo'.
--- End Message ---
--- Begin Message ---
I would expect that if I turn on output buffering, echo something,
throw an exception,
and catch the exception, nothing will have been actually output. That
doesn't seem
to be the case. Throwing an exception seems to defeat output buffering.
In the following code, I would not expect to see the <h1>, but I do.
<?
try {
ob_start();
echo '<h1>You should not see this!</h1>';
throw new Exception('<h2>This should be the first output.</h2>');
exit( 'Contents: ' . ob_get_clean());
}
catch (Exception $ex) {
exit('<h2>Exception:</h2>' . $ex->getMessage());
}
I'm exercising that code on PHP 5.2.4 and 5.2.8.
Does anybody know why throwing an exception seems to override
ob_start(), flushing the buffered output? Is there a workaround?
Thank you,
Leif Wickland
--- End Message ---
--- Begin Message ---
Output buffer is flushed at the end of script. When you throw that exception
in try block, this command: exit( 'Contents: ' . ob_get_clean()); never
executes and it continues to catch block where you are outputing exception
message, and it is added to the buffer, then the script ends and buffer
flushes.
=======================
"Leif Wickland" <leifwickl...@gmail.com> pí¹e v diskusním pøíspìvku
news:c5b9ee2c0902022202v6e2a071emfb062aa868ed7...@mail.gmail.com...
>I would expect that if I turn on output buffering, echo something,
> throw an exception,
> and catch the exception, nothing will have been actually output. That
> doesn't seem
> to be the case. Throwing an exception seems to defeat output buffering.
>
> In the following code, I would not expect to see the <h1>, but I do.
>
>
>
> <?
> try {
> ob_start();
> echo '<h1>You should not see this!</h1>';
> throw new Exception('<h2>This should be the first output.</h2>');
> exit( 'Contents: ' . ob_get_clean());
> }
> catch (Exception $ex) {
> exit('<h2>Exception:</h2>' . $ex->getMessage());
> }
>
>
>
> I'm exercising that code on PHP 5.2.4 and 5.2.8.
>
> Does anybody know why throwing an exception seems to override
> ob_start(), flushing the buffered output? Is there a workaround?
>
> Thank you,
>
> Leif Wickland
--- End Message ---
--- Begin Message ---
'Twas brillig, and Leif Wickland at 03/02/09 06:02 did gyre and gimble:
I would expect that if I turn on output buffering, echo something,
throw an exception,
and catch the exception, nothing will have been actually output. That
doesn't seem
to be the case. Throwing an exception seems to defeat output buffering.
In the following code, I would not expect to see the <h1>, but I do.
<?
try {
ob_start();
echo '<h1>You should not see this!</h1>';
throw new Exception('<h2>This should be the first output.</h2>');
exit( 'Contents: ' . ob_get_clean());
}
catch (Exception $ex) {
exit('<h2>Exception:</h2>' . $ex->getMessage());
}
I'm exercising that code on PHP 5.2.4 and 5.2.8.
Does anybody know why throwing an exception seems to override
ob_start(), flushing the buffered output? Is there a workaround?
This is intended behaviour and just represents the natural application
flow. Exception handling in PHP does not have any concept of "output
buffering" and operates in a generic way. You start output buffering but
you don't explicitly turn it of or clean the contents and thus, when the
script ends (inside your catch block), it will be automatically flushed
(displayed).
If you don't want any output, make sure your catch block first calls
ob_end_clean() before it exits.
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mandriva Linux Contributor [http://www.mandriva.com/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
--- End Message ---
--- Begin Message ---
2009/2/3 Daevid Vincent <dae...@daevid.com>
> Is there a way to create a new property via PHP 5.2.4?
>
> I get a hash back from an authentication server. I'm not guaranteed that
> someone in another department won't add new key/values to the returned
> hash/array. I'm trying to work around that part gracefully so that the
> code doesn't blow up on a customer in such an event. The main try/catch
> will suppress errors already, but I thought it would be nice to be able
> to handle this stuff automatically rather than constantly updating a
> User.class.php file all the time.
>
> "creating new property this->oraclecustomerid with 1122"
>
> but when I try to set the value with the $this->$pkey = $value;
>
> It triggers __call() which then triggers __set() which throws my
> BadProperty exception.
>
> How come $this->$pkey = $value isn't creating/setting a property?
> Or how do I do something like create_property($this, $pkey);
> so that I can then set it via $this->oraclecustomerid = 1122 or
> $this->set_oraclecustomerid(1122) ???
>
> <?php
> function load_from_user_data($user_data)
> {
> //now loop through the rest of the user_data array and assign via a
> set_foo() method
> foreach ($user_data as $key => $value)
> {
> //try
> {
> $pkey = strtolower($key);
> //[dv] this is sort of a hack to
> "automatically" create a new
> property/variable
> // for 'new' hashes key/values we
> may not know about.
> // It's really designed to supress
> errors and they really should
> be added to this User.class.php properly.
> if ( !property_exists($this, $pkey) )
> {
> echo "creating new property
> this->$pkey with $value<br>\n";
> $this->$pkey = $value; //THIS BLOWS
> UP ON THE __set()
> echo "this->$pkey = ".$this->$pkey;
> }
Hey,
well, $this->$pkey is wrong syntax. Try $this->pkey = $value
-eddy
>
> else
> {
> $class_variable = 'set_'.$pkey;
> $this->$class_variable($value);
> unset($user_data[$key]);
> }
> }
> //catch (Exception $e)
> {
> //echo $e->getMessage()."\n";
> }
> }
>
> //should new fields be returned in the $user_data that are
> not
> accounted for above...
> if ($_SESSION['DEVELOPMENT'] && count($user_data))
> {
> echo "<!-- Unaccounted for user_data hashes. Please
> add these into
> User.class.php:\n";
> var_dump($user_data);
> echo "-->";
> }
>
> //THESE TWO LINES FATAL ERROR ON THE __get():
> echo "this->oraclecustomerid = ".$this->oraclecustomerid;
> echo "this->get_oraclecustomerid() =
> ".$this->get_oraclecustomerid();
> }
> ?>
>
--- End Message ---
--- Begin Message ---
Edmund Hertle schreef:
> 2009/2/3 Daevid Vincent <dae...@daevid.com>
>
>> Is there a way to create a new property via PHP 5.2.4?
>>
>> I get a hash back from an authentication server. I'm not guaranteed that
>> someone in another department won't add new key/values to the returned
>> hash/array. I'm trying to work around that part gracefully so that the
>> code doesn't blow up on a customer in such an event. The main try/catch
>> will suppress errors already, but I thought it would be nice to be able
>> to handle this stuff automatically rather than constantly updating a
>> User.class.php file all the time.
>>
>> "creating new property this->oraclecustomerid with 1122"
>>
>> but when I try to set the value with the $this->$pkey = $value;
>>
>> It triggers __call() which then triggers __set() which throws my
>> BadProperty exception.
>>
>> How come $this->$pkey = $value isn't creating/setting a property?
>> Or how do I do something like create_property($this, $pkey);
>> so that I can then set it via $this->oraclecustomerid = 1122 or
>> $this->set_oraclecustomerid(1122) ???
>>
>> <?php
>> function load_from_user_data($user_data)
>> {
>> //now loop through the rest of the user_data array and assign via a
>> set_foo() method
>> foreach ($user_data as $key => $value)
>> {
>> //try
>> {
>> $pkey = strtolower($key);
>> //[dv] this is sort of a hack to
>> "automatically" create a new
>> property/variable
>> // for 'new' hashes key/values we
>> may not know about.
>> // It's really designed to supress
>> errors and they really should
>> be added to this User.class.php properly.
>> if ( !property_exists($this, $pkey) )
>> {
>> echo "creating new property
>> this->$pkey with $value<br>\n";
>> $this->$pkey = $value; //THIS BLOWS
>> UP ON THE __set()
>> echo "this->$pkey = ".$this->$pkey;
>> }
>
>
> Hey,
> well, $this->$pkey is wrong syntax. Try $this->pkey = $value
>
there is nothing wrong with $this->$pkey.
the question is what is __set() doing, if it's throwing an exception
for undefined properties then obviously it with 'blow up'.
I would suggest looking into using an array inside the object to
store all user data, you can still use some setter methods for user fields
that are known at compile time and for the rest you just stuff the extra/unknown
fields into the array, something like:
class Test {
private $data = array();
function loadUserData($data) {
foreach ($data as $key => $val) {
if (method_exists($this, 'set_'.$key)
$this->{'set_'.$key}($val);
else
$this->data[ $key ] = $val;
}
}
}
> -eddy
>
>
>
>> else
>> {
>> $class_variable = 'set_'.$pkey;
>> $this->$class_variable($value);
>> unset($user_data[$key]);
>> }
>> }
>> //catch (Exception $e)
>> {
>> //echo $e->getMessage()."\n";
>> }
>> }
>>
>> //should new fields be returned in the $user_data that are
>> not
>> accounted for above...
>> if ($_SESSION['DEVELOPMENT'] && count($user_data))
>> {
>> echo "<!-- Unaccounted for user_data hashes. Please
>> add these into
>> User.class.php:\n";
>> var_dump($user_data);
>> echo "-->";
>> }
>>
>> //THESE TWO LINES FATAL ERROR ON THE __get():
>> echo "this->oraclecustomerid = ".$this->oraclecustomerid;
>> echo "this->get_oraclecustomerid() =
>> ".$this->get_oraclecustomerid();
>> }
>> ?>
>>
>
--- End Message ---
--- Begin Message ---
Hi gang,
I was wondering if there is way to find out what is the time that
every day ends? I am planning to add this to the first page on an
interface I am developing.
--
Thodoris
--- End Message ---