From owner-freebsd-questions@freebsd.org Fri Feb 1 14:14:29 2019 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5CC4714B4060 for ; Fri, 1 Feb 2019 14:14:29 +0000 (UTC) (envelope-from markmoellering@psyberation.com) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 7E8478FCC5 for ; Fri, 1 Feb 2019 14:14:28 +0000 (UTC) (envelope-from markmoellering@psyberation.com) Received: by mailman.ysv.freebsd.org (Postfix) id 3D34714B405B; Fri, 1 Feb 2019 14:14:28 +0000 (UTC) Delivered-To: questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 190EF14B405A for ; Fri, 1 Feb 2019 14:14:28 +0000 (UTC) (envelope-from markmoellering@psyberation.com) Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id AD47D8FCC4 for ; Fri, 1 Feb 2019 14:14:27 +0000 (UTC) (envelope-from markmoellering@psyberation.com) Received: by mail-qt1-x830.google.com with SMTP id n32so7548890qte.11 for ; Fri, 01 Feb 2019 06:14:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=psyberation-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rlH/SGWtlmV32JW6IwcomiO4kUOoX+L6Sdt0xrbz7sg=; b=MrTckoBEewGtaiZE61rxAb3uC830hYHILVe4SYzgeUWWTrU4Fsh7cSz7Rxjaxxq/GE shZCMTrIa4k00JYV53gbWx1zqhntfXTIMGUews2kRc0w2//wG5vD4nkQNpj93xn7ueDD fIzxsAxZCw1Jh3jHD2Xts84JGLYNqQRng2z3OzNTM1oSmJN7B/qT4laBtMvb39F+aNSf jWa+riujIo+v2DBxusqxI2LaxFxoI46BFPvUA7RCRmNs5tkhHnV9pFXqKcseUWsQahLb FrgYLBd5myCjrdgP362enzSiYgCbCxDL8XXCeWeUcCJuhgfNtRyePRLo/N6nX+W44ByR i33w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rlH/SGWtlmV32JW6IwcomiO4kUOoX+L6Sdt0xrbz7sg=; b=Trh26uGloPeI4ok2ojS7LnSrg6FfY/+zJRqFqirjRMd6r7/LCwWPN3adGqBKQ+adxl NcSi38+erPUL2IK+dB8lYlDjVp7vGqXcTV0S5uaP2RSmvqK7rzcbQjIP0vSV95PA1Z8L RGWdL2SxRHhB+xiGhqEnn1q4kD7p/JpJ3ELVedVMYJkWkKqNt4j1a1JbaaXnP6sQin3S X40tWwmCWuq6WKNlVETlFb/DlPWoa+shIK3SsdQgzxEnH4RYk5F1toBvJxjjp4vc9Cnw wm4Lj9DRsZSzrQDiF7WuiZxwcvYA70KP2dJx+4by3I684c0hqfAMl6whGwIDRYJZaeGS VZEw== X-Gm-Message-State: AJcUukdjjnGJdistPonZcnCTgsgg47YND62eQ2+EmnxIM7yuBsf8ZP+B k8tQ6ZRmpKfhrPeNpyqG6AfqGN+0G2qPjEmXUV0Ngw== X-Google-Smtp-Source: ALg8bN7xn40HSxH35mHhwD28iFCqVEbk3U/l5NCywiEnRshhdR9WqOLsYI1naPbCpmht0pPX6V6iGrSdzXqJ+al9aKw= X-Received: by 2002:aed:23c5:: with SMTP id k5mr39391650qtc.39.1549030466948; Fri, 01 Feb 2019 06:14:26 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Mark Moellering Date: Fri, 1 Feb 2019 09:14:16 -0500 Message-ID: Subject: Re: Problems with JSON and PHP To: Doug Hardie Cc: questions@freebsd.org X-Rspamd-Queue-Id: AD47D8FCC4 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-6.95 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[]; NEURAL_HAM_SHORT(-0.95)[-0.949,0] Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 01 Feb 2019 14:14:29 -0000 On Fri, Feb 1, 2019 at 2:06 AM Doug Hardie wrote: > I have installed apache24, php72 and a host of other somewhat related php > packages. I can't seem to get apache to run a php script that includes > json_encode. > > test# pkg info | grep php > mod_php72-7.2.14 PHP Scripting Language > php72-7.2.14 PHP Scripting Language > php72-curl-7.2.14 The curl shared extension for php > php72-filter-7.2.14 The filter shared extension for php > php72-gd-7.2.14 The gd shared extension for php > php72-hash-7.2.14 The hash shared extension for php > php72-json-7.2.14 The json shared extension for php > php72-mbstring-7.2.14 The mbstring shared extension for php > php72-mysqli-7.2.14 The mysqli shared extension for php > php72-openssl-7.2.14 The openssl shared extension for php > php72-pear-1.10.6 PEAR framework for PHP > php72-pear-Services_JSON-1.0.3 PHP implementation of json_encode/decode > php72-pecl-mcrypt-1.0.1 PHP extension for mcrypt, removed in PHP 7.2 > php72-pecl-xdebug-2.6.1 Xdebug extension for PHP > php72-session-7.2.14 The session shared extension for php > php72-xml-7.2.14 The xml shared extension for php > php72-zip-7.2.14 The zip shared extension for php > php72-zlib-7.2.14 The zlib shared extension for php > > test# pkg info | grep apache > apache24-2.4.38 Version 2.4.x of Apache web server > > test# pkg info | grep mod_ > mod_php72-7.2.14 PHP Scripting Language > > Server has been rebooted several times. > > test# freebsd-version -ku > 12.0-RELEASE > 12.0-RELEASE > > In /usr/local/www/apache24/data is the file: > test# more /usr/local/www/apache24/data/test.php > print "Hello world"; > > $myObj = (object) array(); > $myObj->name = "John"; > $myObj->age = 30; > $myObj->city = "New York"; > > $myJSON = json_encode($myObj); > > echo $myJSON; > ?> > > > Running it by hand works: > test# php /usr/local/www/apache24/data/test.php > Hello world{"name":"John","age":30,"city":"New York"}test# > > Accessing it via a browser yields: > Hello world > > and an error: > test# tail -1 /var/log/httpd-error.log > [Thu Jan 31 22:29:25.506018 2019] [php7:error] [pid 1586] [client > 10.0.1.251:53459] PHP Fatal error: Uncaught Error: Call to undefined > function json_encode() in /usr/local/www/apache24/data/test.php:9\nStack > trace:\n#0 {main}\n thrown in /usr/local/www/apache24/data/test.php on > line 9 > > The info.php file in that directory works properly when accessed via the > browser. Obviously I have got something setup wrong. I have not been able > to figure it out. ktrace never shows any attempt to access anything I can > see identifiable with json_encode. I would appreciate any ideas on how to > fix this. Thanks > > > -- Doug > > I use php and my biggest complaint is the way it handles errors. I think what is happening is that your Object Definition has a syntax error but php is complaining about the json_encode. I believe (from the php.net docs) that it should be $myObj = new stdClass(); > $myObj->name = "John"; > $myObj->age = 30; > $myObj->city = "New York"; > I highly recommend the php.net documentation. It shows different ways to do this and it looks like you merged two different styles that are incompatible. As a suggestion, in the future, assume it is a php problem and try Stack Exchange first. If everyone there says, "everything looks good, could be your distro / OS", then post to the FreeBSD List and explain what steps you have already taken. It will help keep responses much more friendly. -- Mark