« first day (1184 days earlier)      last day (3990 days later) » 

08:08
well, it's good to poke pplz into some quality here.
imagine, you take a new job and they used stuff from SO all the time.
It would be horrible if I ever have a job where people rely on SO that much
@zerkms because we have this.. cv-pls.com
that's thanks to @crypticツ
08:19
@zerkms more info?
enough
Can anyone tell me why this code returns an empty page?
<?php

	set_time_limit(3);

	$x = @file_get_contents('http://aviationweather.gov');

	if($x === false)
	{
		die('down');
	}

	die('ok');

?>
@DannyBeckett error_reportng E_ALL + display_errors + stop using @
Most likely a FATAL ERROR with display errors off. - and what @zerkms said.
user652649
and echo something, for example xD
08:27
ah I see, trying without the @ now
@Wes there is die already
@DannyBeckett and actually forget @ in php exists
@zerkms I unfortunately have no choice, e.g $dom->loadHTML($html); (without an @) returns a bunch of Warnings on external pages
the output I now get is
Warning: file_get_contents(aviationweather.gov): failed to open stream: No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\av\test.php on line 5

Fatal error: Maximum execution time of 3 seconds exceeded in C:\xampp\htdocs\av\test.php on line 5
@DannyBeckett use libxml_use_internal_errors(true);
I'm really struggling here, since $x should be false :S
@DannyBeckett so? I think the warning message is self-descriptive
08:30
@zerkms it is, but it doesn't correspond with my code
var_dump($x);
(aviationweather.gov is down)
I'd say you're looking for specifying the connection timeout value.
@zerkms I can't get any output
Fatal error: Maximum execution time of 3 seconds exceeded in C:\xampp\htdocs\av\test.php on line 5
you get a blank page because of that, x is not set, execution doesn't get that far ...
08:31
3 seconds is way too much =oP
ok, gonna try removing that
actually, no point, it just has the same fatal error after 30 seconds instead
use curl with timeout less than your max_execution_time
you dont set time limit
that won't allow you to output the die() message
that is not done via set_time_limit() but stream_set_timeout() resp. an ini setting for the default and/or stream options.
^ that
08:32
16
Q: Does file_get_contents() have a timeout setting?

Flora ClintonI am calling a series of links using file_get_contents method in a loop. Each link may take more than 15 minutes. Now, I worry whether php's file_get_contents have any time out period... if yes, it will time out with a call and move to next link. I don't want to call the next link without the pri...

Looks like I'm looking for default_socket_timeout
:)
well, why are you using file_get_contents at all, why not fsockopen and pass your timeout to that, if you are just checking a server is up, then just do a HEAD request, you do not need to do any more ...
@JoeWatkins I'm not. I need the data returned. This is just a short example. This is the real thing:
class XMLToJSON
	{
		public static function FromURL($url)
		{
			$xml = @file_get_contents($url);

			if($xml === false)
			{
				return false;
			}

			$xml = str_replace(array("\n", "\r", "\t"), '', $xml);
			$xml = trim(str_replace('"', "'", $xml));
			return json_encode(simplexml_load_string($xml));
		}
	}
a nice example of SRP violation
user652649
lol
@zerkms care to elaborate?
yeah I Googled it before asking
What he means is that you should have one component to deal with the remote access (fetching the URL) and the other with processing that data then.
So in the case you have, you can create a setting with the URL fetcher for a timeout value.
for something that's a few lines long? nah I'm ok thanks
user652649
@DannyBeckett you should have 1 function that fetches and a remote page and returns a string, and another one that converts a string "from xml to json"
don't need it be any more abstract
08:36
And you won't place the timout on the whole (!) script.
every project is started like that :-)
"I won't touch it anymore"
I never use file_get_contents for remote streams, it is a trick, it was never really meant for that (that's why it has no timeout parameter), the fact that PHP can understand an http:// stream and read it doesn't make it the optimal solution, the optimal solution is the one that you can get enough control over to do what you want to do, either with sockets, or if you are super lazy then curl ... you probably could set some ini parameters to get the correct behaviour for this one piece of code
but it's not a good idea to do so, in my opinion ...
I'm gonna try default_socket_timeout, brb
@JoeWatkins Well for HTTP there is PHP's HTTP extension.
not php's extension ... you mean pecl_http ?
08:38
which is for PHP, isn't it?
yeah but it's not part of php is it ... it's in pecl :)
that works perfectly
php.net/http - for those who don't know it.
thanks for your help everyone
@zerkms It does not break the SRP, because FromURL method belongs to XMLToJSON. It still satisfies "one reason to change"
08:40
@hakre it's not usually a good idea to suggest solving a problem with anything in pecl though, because then you have to explain how to use pecl, then you have to explain that on shared hosting you cannot use pecl, then we end up talking about how crap shared hosting is ... curl is bundled, everyone is likely to have it ... and I've never used an installation of php without sockets, so that's even better ...
@djay there are 2 different tasks performed there: data retrieval and data processing
yeah exactly
@djay I don't see how converting xmltojson from a local file should be a different method
and then xmltojson from a file on FTP
@JoeWatkins if curl is bundeled - fair point btw. - then PHP streams use curl. So if you say use curl, you can say use file_get_contents. All fine and dandy.
@zerkms I never need to convert from local, it's always a URL
08:42
@zerkms You're talking about Separation of concerns. That breaks the SoC, but it does not break the SRP.
:)
hence why I don't need it any more abstract
@djay I don't see how it doesn't violate SRP
@zerkms it has a single responsibility: Turn an XML document located via URL into a JSON string.
@hakre then every godlike object can be treated as not violating SRP
just because you can fit its all job into a single statement
08:44
@zerkms This is a method object, not a god object.
I agree with you
But I understand your criticism, don't shout at me :)
this - is, but that way you can explain any godlike object
"an object that retrieves some data from database and uploads kitten pic to a filehosting and then it modifies iptables rules"
Well let's perhaps say it this way: The code in it's current form might not yet violate SRP because of the way it is used. However, coming maintenance and future changes of requirements, there is high risk with the current design to not be fitting any longer.
@zerkms You're thinking about details, while you should think about abstractions. For example, take an interface interface XMLToJSON { public function FromURL($url); }, get it?
08:46
@djay this interface doesn't make much sense to me
@hakre don't quote me on this, but pretty sure that's been removed (stream using curl) ... there was certainly talk of removing it ...
it's tricky to test it
If anyone cares, the code runs a chat bot in the Aviation room
@djay But you did not throw exception in case it didn't work. You just ran into FATAL ERROR due to timeout and then you were puzzeled.
@DannyBeckett which aviation room?
The requirement will NEVER change. It just needs to fetch an external XML page and return the JSON

 The Hangar

General discussion about aviation.stackexchange.com The white ...
08:48
@DannyBeckett I only wrote that if the requirements change, there is high risk. If the requirements do not change, this is fine.
yeah I'm agreeing with you @hakre
that fixed the issue btw
I have problems logging in there, no clue why ... ???
@hakre I have logged there
may be you don't have enough rep yet :-P
try here:
(then click the Stack Exchange logo in the top bar and choose Chat)
class XMLToJSON
{

	protected function fetchURL($url)
	{
		// I wish I could abstract this too,
		// but there's no need to for demonstration purposes
		$xml = file_get_contents($url);

		if ($xml === false) {
			throw new RuntimeException('Jeez');
		}

		$xml = str_replace(array("\n", "\r", "\t"), '', $xml);
		$xml = trim(str_replace('"', "'", $xml));

		return simplexml_load_string($xml);
	}


	public function build($url, $type = 'json')
	{
		switch($type){

			case 'json':

				return json_encode($this->fetchURL($url));
maybe this would make a bit more sense..
08:54
@djay how would you test it?
it == XMLToJSON::fetchURL()
XMLToJSON no longer makes sense as a class name..
but thanks for the guidance :)
@djay ?
there is no static methods in the code
XMLToJSON::fetchURL() is just a signature
then why do you call with ::?
I don't call, it's a method signature
08:57
O.o
my point was - how would you test it with file_get_contents inside
@zerkms Do you test private and protected methods?
yeah you need ini_set('default_socket_timeout', 5); on top of the class
I don't directly, and I don't see how it's relevant
anyway, I'm gonna stop bugging you guys
because you've actually been very helpful
cheers! seeya
08:58
@zerkms As I told before, file_get_contents() should be abstracted, then it can easily be mocked
@djay it should be, in a separate class
then this one will make sense
this is was my point half an hour ago
@zerkms yeah everyone knows that... - that it should be in separated class, but it comes down to SoC again (not the SRP)
may be I don't completely understand SRP then
@zerkms Do you understand what "One reason to change" means ?
actually reading about it
09:02
@djay it is in PHP via wrappers, you can just mock http:// away here.
@DannyBeckett no no not really, if you put "ini_set()" at the top of your class, you end up causing "slide-effects"
@hakre yeah exactly
@djay I'd say you configure the PHP framework. The side-effect is intended.
well, here are 2 reasons to change: 1. the datasource can change 2. the simplexml may be demanded to be changed to DOM
am I missing something again?
No, that are two more realisitic points what can happen.
yeah, you're missing the whole point
09:04
ohhhh :-S
datasource and xml - are details, not abstractions
bye guys!
"Why was it important to separate these two responsibilities into separate classes?
Because each responsibility is an axis of change. When the requirements change, that
change will be manifest through a change in responsibility amongst the classes. I"
I don't see how changing simplexml to DOM doesn't fit it
Because those requirements so far do not change :)
So far, functional decomposition is enough to solve the problem.
So actually OOP is not needed here.
09:07
So if I say "my requirements won't change" I can fit everything into a single method?
If they actually do not change, yes. But what we know is that requirements do change.
objectmentor.com/resources/articles/srp.pdf states it as an axis of change, not the fact it will be changed tomorrow
so moving from simplexml to DOM is a fair change, since the former sucks
locating one or more axis of change is needed when you design your objects.
the same as moving from file_get_contents to sockets for the very same reason
I'm feeling dumb but I don't understand you guys :-(
Let's shake this a little to get the head open.
Maybe it helps.
So what would you roughly say is Code Quality?
09:10
it's a combination of some metrics/requirements, either numerical or just declarative (like SRP)
@hakre code quality is WordPress and Yii :P
Okay. So you can take a look on code and then say SRP applied yes/no, so Quality is good/not-so-good. Right?
well, I thought I could
bit in general one could, indeed
Okay, actually code quality is the property of the code to get the job done.
Get's it the job done well or not so well?
I'm not sure the latest statements are valid
I don't see how code quality may affect the quality of the job the code does
it can be ugly but with impressive results, the opposite is true as well
09:13
That is per the requirements again: The requirements say what the code has to do. If the code does not match the requirements (it does not get the job done sloppily said), it's of bad quality.
So now for the broader view: What you wrote about SRP still applies here.
Let's take that joke about Wordpress. Let's create the impression Wordpress would contain code that "gets the job done."
Does it?
it does
Does it meets users needs? Not really that well. Users needs are either matched by automattic.com running Wordpress for you (so you do not need to care) and for those agencies how get low paid income for maintaining Wordpress for their customers.
Those who actually develop and maintain Wordpress have a lot of frustrating, repeating work, often resulting in something like carrying boxes from one side of the room to the other and back.
The development of Wordpress has actually stalled.
So it does not get the job done. It did in it's early days and that's where it has it's popularity from.
I went through objectmentor.com/resources/articles/srp.pdf and probably now I get why it's SoC not SRP violation
so the key here is about different behaviours not implementation details, isn't it?
Most likely yes.
But I would say the biggest difference is to first a) find out about the requirements and then b) have a good nose which areas are going to change.
so that you can actually say what concerns are and say which object is responsible for what exactly.
You can for example introduce a full flavored stream abstraction to fetch data from stores that might or might not be remote, can or can not be cached either on the protocol and on the access level etc. pp..
But if that is out of any requirements, you might have a nice system, but imagine there is an error fetching a document, most likely many parts might need to change.
So you have not separated cleanly the concepts.
Take the example of Danny. What needs abstraction is less the PHP code, but in his case in the JS code that you didn't see so far probably.
There is one part that parses and transforms the JSON document.
But it's just inlined so far in the ajax response event.
Again, functional decomposition can already do the job here because the overall application is not complex.
But you do not get the re-usable components in the long run from it.
09:37
just to confirm I've carefully read it, thanks
and while we're at it: What actually needs to be done in this case is that the remote fetching is abstracated so that multiple sources for the weather information can be contacted in case one is down (a website that is down caused this maintenance problem with the code).
09:53
@Lusitanian I don't get it?
user2286243
10:11
8
Q: How replace variable in string with value in php?

messi fanI have string like this in database(actual string contains 100s of word and 10s of variable) i am a {$club} fan i echo this string like this $club = "Barcelona"; echo $data_base[0]['body']; My output is i am a {$club} fan. I want i am a Barcelona fan How can i do this?

user2286243
Isn't there some native PHP way to do that without writing your own functions?
@SantaClaus you have already received answers
oops, not you, but there are already answers given
@bwoebi thanks :)
user2286243
Is there any built in PHP function for that?
user2286243
Like we use double quotes
10:13
Hi all.
user2286243
@MaciejCzyżewski Hi
@SantaClaus there are already answers given
user2286243
cv-pls?
@SantaClaus Forgot about that idea right away. It's a dumb thing to do
At least get away from the "replace with variable" idea.
And go towards "replace some placeholder with some value"
@NikiC no problem… it was my first guess anyway ;-)
10:39
@zerkms uh, where the f did the "minimal understanding" reason go?!
@NikiC close as primarily opinion based :-S
user2286243
@zerkms Done. Even answers are downvoted
nice
now I can go sleep
22
A: Improving "demonstrate a minimal understanding" close reason

Shog9Take 3: Closing camels, not gnats - poorly-written questions are Unclear First off, a big thanks to everyone who pitched in here - trying to distill a broad class of (often ill-defined) problems into a clear, helpful bit of guidance is quite a challenge - I'm happy to see so many folks willing t...

@bwoebi can't they just leave the damned close reasons alone?
@NikiC ask them, not me, hehe
11:08
Oh I have a regex question :D
@hakre cmon.
Yeah, I really do not understand why I can't get it to work with subpatterns while when I expand the subpattern it works.
I've read that subpatterns are atomic, so I changed their matching from greedy to non-greedy which helped a lot to get the pattern going.
but still, with this one subpattern I can't get it to work.
morning!
why is date('h:i', 0); returning 01:00
and not 0?
user2286243
@Rikard It is returning me 12:00
hmmm.... strange
11:14
@Rikard where are you?
Sweden
h 12-hour format of an hour with leading zeros 01 through 12
It does not have 00, so it has 01?
its 12.14 in sweden now
and output depends on PHP version: 3v4l.org/59LOo
@hakre example pls.
@Rikard on my clock I have 12:15 ^^
11:15
@hakre +1, interesting.
3v4l.org/JfKOD - more verbose
I tend to say that there is a bug.
@hakre but now is ok.
I wanted to calculate a date('h:i', strtotime() - strtotime()) and when it was zero I am getting 01:00 (!) how else to do this?
@Rikard install new php 5.5
@MaciejCzyżewski is it? I thought UNIX Epoch starts at 00:00:00 not at 01:00:00
user924016
11:17
Mooorning
good mooorning :D
user924016
=]
@RonniSkansing :-^^
user2286243
@hakre Do you know the reason for such behaviour in PHP?
user2286243
Output for 5.1.0 - 5.5.8
1970-01-01 01:00:01
Output for 4.3.0 - 5.0.5
1970-01-01 12:00:01
11:19
@hakre psss, I'll tell you a secret: Timezone.
@SantaClaus Europe/Amsterdam - UTC+1
@hakre that's amazing too... 3v4l.org/BV7Ca
USE TIMESTAMP!
user2286243
@hakre No, why different version of PHP gives different result?
@SantaClaus it was probably a bug that was fixed at one point
Ok, posted a question with this... stackoverflow.com/questions/21074050/…
user924016
11:30
@Rikard i get 0 3v4l.org/t3SJO
@RonniSkansing, the question is why date() adds one hour to that ... ?
This line make my live sense. strtotime('2014-01-01') - strtotime('2014-01-01')
@RonniSkansing
user924016
@MaciejCzyżewski line makes my live sense?
Hi, dont you guys know if there is a framework in php that works similary to how RoR or asp mvc works?
any magento expert here ?
11:40
@Kikaimaru maybe Laravel or Symphony
@SantaClaus it doesn't, but that's a question of using the right function: 3v4l.org/QOcpV
@Kikaimaru similar in which sense? PHP actually in itself works similar to those.
@PranshuJain yes: you need to upgrade to 1.8, that solves it.
@hakre solves what ?
@PranshuJain what you wanted to ask about.
:)
user924016
hihi
@hakre i need some help with custom option.
i am trying since long back
but i am unable to acheive dependent custom options for magento
@hakre Pl help
11:43
Those are normally not dependent.
how to make like that ?
@PranshuJain You go to certified Magento Partner, tell them what you need and they provide you an Add-On. Done.
I always do it that way.
I am not having much of money, i want to code it with help of experts like you
For the options I think you can also do it with the template if dependend means display based on radio buttons. There is also a Magento question on site (at least one) that asks about exactly that.
@PranshuJain Well I've got weekend, so I normally try to prevent to deal with Magento as much as possible.
yes dependent means display based on radio,'
11:47
So no thank you.
@hakre Just give me a path to follow or little guidance, it wouldn;t take much of you i hope.
user924016
@PranshuJain do you know php?
yes.
@RonniSkansing yes,
user924016
@PranshuJain how about boiling up some code then, and seeing if you can get somewhere youself?
user924016
=]
11:50
@RonniSkansing i am messing up since a long back, i have to complete in the given timeframe
@hakre no it doesnt, similar in sense that it uses templating engine for views for example, which codeigniter and cacephp doesnt. Active record, or any kind of ORM would be nice too (included in framework)
@MaciejCzyżewski I'll look ath them thanks
user924016
@PranshuJain so you have a deadline, and you been paid to make a feature which is outside of your skillset and you do not want to buy this functionality?
@Kikaimaru PHP is a templating engine. Especially in context of HTML templates.
@Kikaimaru np/
@hakre yeah, i guess thats one of the many problems..
11:52
@RonniSkansing buying is costlier then project cost.
user924016
@PranshuJain 50$ ?
@Kikaimaru No it first of all is like it is. The problem most often is, that we educate ourselves too little what that means to then work well with it.
@RonniSkansing 35
E.g. if you think that an ORM should be included in a framework, think again.
user924016
@PranshuJain oh... I do not get it
11:54
@hakre look im just spoiled with how easy and clean RoR is, and i want something similar in php, because php alone is not useable at all
@Kikaimaru Okay, RoR, if you have an hour, watch this: confreaks.com/videos/…
@RonniSkansing So what to do now ?
ThW
ThW
Morning
@hakre so no help for me ?
If you're looking for the juice, the magic and it all together incl. your ORM and what not, there's github.com/ICanBoogie/ICanBoogie (just came out by spinning the framework wheel of fortune)
@PranshuJain Yes, no help for you. Sorry.
11:57
@hakre i am not looking for anything that has "echo" in tutorial
user924016
@PranshuJain start coding
user924016
or start paying
@Kikaimaru right, because you're not using STDOUT in your application. I understand. But if you didn't knew it, you can use (string) instead of echo.
@RonniSkansing thank you :)
user924016
np =]
user924016
11:58
we can help you with code ;)
@ThW good morning :D
@RonniSkansing that would be very helpful of you.
@hakre i think you are missing the point, but nevermind the frameworks that someone posted are good, thanks

« first day (1184 days earlier)      last day (3990 days later) »